So, i have pydantic model with string field
class MyPydanticModel(BaseModel):
name: Optional[str]
And i want make max length for this field is 10. How can i do this?
You can use constr
:
from pydantic import BaseModel, constr
class MyPydanticModel(BaseModel):
name: Optional[constr(max_length=10)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With