You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportAnnotated, LiteralfrompydanticimportBaseModel, FieldclassDice(BaseModel):
result: Annotated[Literal[1, 2, 3, 4, 5, 6], Field(description="The result of a 1d6")] |None=NoneDice.model_validate({"result":"1"})
pydantic_core._pydantic_core.ValidationError: 1 validation error for Dice
result
Input should be 1, 2, 3, 4, 5 or 6 [type=literal_error, input_value='1', input_type=str]
For further information visit https://errors.pydantic.dev/2.10/v/literal_error
The text was updated successfully, but these errors were encountered:
@Viicos What's the concern with making this the out of the box behavior? That issue says it was rejected by the team because literals "should" be strict, but it's not clear to me why we don't see this as equivalent to the following, where the coercion does work:
classDice(BaseModel):
result: Annotated[int, Field(description="The result of a 1d6", ge=1, le=6)] |None=None
As reported on pydantic/pydantic-ai#1691:
The text was updated successfully, but these errors were encountered: