Pydantic defines data shapes as Python classes and validates, converts and serializes data using type hints; FastAPI uses it for request bodies, response models, settings and the JSON Schema in the OpenAPI docs.
A missing field or a wrong type is rejected before your function runs, and values are coerced where sensible (the string "5" becomes the integer 5 in default lax mode).
Pydantic v2 (current) uses model_dump() and model_validate() (replacing the v1 dict() and parse_obj()), and its validation core is written in Rust for speed.
Loading…