pseco
12/16/2025, 9:58 AMpesos: List[float] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2],
description=(
""
""
),
title=""
)Marvin
12/16/2025, 9:58 AMMarvin
12/16/2025, 10:00 AMField(min_length=3, max_length=4).
If you’re defining this on a Pydantic model:
from typing import List
from pydantic import BaseModel, Field
class Params(BaseModel):
pesos: List[float] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2],
min_length=3,
max_length=4,
description="",
title="",
)
If you want it directly as a flow parameter:
from typing import Annotated, List
from pydantic import Field
from prefect import flow
@flow
def my_flow(
pesos: Annotated[List[float], Field(min_length=3, max_length=4)] = [0.4, 0.2, 0.2, 0.2]
):
# your logic here
return pesos
Both approaches only allow lists of length 3 or 4; anything else will raise a validation error.
Note: If you happen to be on Prefect 2.x (Pydantic v1), use `min_items`/`max_items` or conlist, e.g.:
from pydantic import conlist, BaseModel
class Params(BaseModel):
pesos: conlist(float, min_items=3, max_items=4) = [0.4, 0.2, 0.2, 0.2]pseco
12/16/2025, 10:13 AMMarvin
12/16/2025, 10:13 AMMarvin
12/16/2025, 10:15 AMmin_length / max_length
from typing import List
from typing_extensions import Annotated
from pydantic import BaseModel, Field
class Params(BaseModel):
pesos: Annotated[List[float], Field(min_length=3, max_length=4)] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2]
)
# This should raise a ValidationError (too few items)
# Params(pesos=[0.1, 0.2])
- Pydantic 1.x: use min_items / max_items (or conlist)
from typing import List
from pydantic import BaseModel, Field
class Params(BaseModel):
pesos: List[float] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2],
min_items=3,
max_items=4,
)
or
from pydantic import BaseModel, conlist
class Params(BaseModel):
pesos: conlist(float, min_items=3, max_items=4) = [0.4, 0.2, 0.2, 0.2]
If you mean per-item bounds (e.g., each weight between 0 and 1):
- Pydantic 2.x:
from typing import List
from typing_extensions import Annotated
from pydantic import BaseModel, Field
Number = Annotated[float, Field(ge=0, le=1)]
class Params(BaseModel):
pesos: Annotated[List[Number], Field(min_length=3, max_length=4)] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2]
)
- Pydantic 1.x:
from pydantic import BaseModel, conlist, confloat
Weight = confloat(ge=0, le=1)
class Params(BaseModel):
pesos: conlist(Weight, min_items=3, max_items=4) = [0.4, 0.2, 0.2, 0.2]
If you’re still seeing “max works but min doesn’t,” please share:
- your Pydantic version
- an example input that should fail the min check but doesn’t
I can reproduce and pinpoint the issue from there.pseco
12/16/2025, 10:16 AMpseco
12/16/2025, 10:16 AMMarvin
12/16/2025, 10:16 AMMarvin
12/16/2025, 10:17 AMfrom typing import List
from typing_extensions import Annotated
from pydantic import BaseModel, Field
class Params(BaseModel):
pesos: Annotated[List[float], Field(min_length=3, max_length=4)] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2]
)
# Fails (too few items)
# Params(pesos=[0.1, 0.2])
# Fails (too many items)
# Params(pesos=[0.1, 0.2, 0.3, 0.4, 0.5])
# OK (3 or 4 items)
# Params(pesos=[0.1, 0.2, 0.3])
Pydantic 1.x — use min_items/max_items or conlist
from typing import List
from pydantic import BaseModel, Field
class Params(BaseModel):
pesos: List[float] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2],
min_items=3,
max_items=4,
)
or
from pydantic import BaseModel, conlist
class Params(BaseModel):
pesos: conlist(float, min_items=3, max_items=4) = [0.4, 0.2, 0.2, 0.2]
Common gotcha: if you provide a default of length 4 (via default_factory), omitting pesos will always pass. To actually see the “min items” error, pass a shorter list:
Params(pesos=[0.1, 0.2]) # should raise a ValidationError
If you still see “max works but min doesn’t,” please share your Pydantic version and the exact input that isn’t failing so I can reproduce.pseco
12/16/2025, 10:20 AMMarvin
12/16/2025, 10:20 AMMarvin
12/16/2025, 10:27 AMfrom typing import List
from typing_extensions import Annotated
from pydantic import BaseModel, Field
class Params(BaseModel):
pesos: Annotated[List[float], Field(min_length=3, max_length=4)] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2]
)
Pydantic 1.x
from typing import List
from pydantic import BaseModel, Field
class Params(BaseModel):
pesos: List[float] = Field(
default_factory=lambda: [0.4, 0.2, 0.2, 0.2],
min_items=3,
max_items=4,
)
# or
from pydantic import BaseModel, conlist
class Params(BaseModel):
pesos: conlist(float, min_items=3, max_items=4) = [0.4, 0.2, 0.2, 0.2]
2) Prefect UI vs server-side enforcement
- The Prefect 3 UI may allow you to enter 2 items in the form, but the server will reject the run at creation if enforce_parameter_schema is enabled on the deployment (true by default) and your flow parameter is typed with your Params model.
- Make sure your flow signature actually uses the model so the schema is generated:
from prefect import flow
@flow
def my_flow(params: Params):
...
If you still see a run start with only 2 items (no validation error), it usually means one of:
- The flow parameter is not typed as Params (so the deployment has no schema for it)
- You’re on Pydantic 1.x but using min_length instead of min_items
- Schema enforcement is disabled for the deployment/run
If you can share:
- Prefect version (prefect version) and Pydantic version (import pydantic; pydantic.__version__)
- Your flow signature
- How you’re starting the run (UI/CLI/API)
…I can pinpoint exactly why the 2-item case is slipping through.