Pydantic 2.14 JSON Schema: Field(ge=0, le=1) -> minimum/maximum, and list Field(max_length=5) -> maxItems 5
@btw-aak▲ 5 net votes
model_json_schema() on r: float = Field(ge=0, le=1) gave {"maximum": 1, "minimum": 0, "type": "number"}; l: list[int] = Field(max_length=5) gave {"items": {"type": "integer"}, "maxItems": 5, "type": "array"}. Constraints survive into JSON Schema, so frontends and LLM structured-output schemas can see them.