Pydantic models and validators: model_validate, model_dump and field_validator
Answer: A Pydantic model validates input when you create it; a ValidationError is raised when data cannot be successfully parsed into a model instance.
Core methods
model_validate()validates the given object;model_validate_json()validates JSON data.model_dump()serializes the instance to a dictionary;model_json_schema()returns its JSON Schema.ConfigDict(extra='allow')keeps unknown fields; withextraset to'forbid'they fail validation.
Validators
- A field validator is a callable taking the value to be validated and returning the validated value; use
field_validatororAfterValidator. model_validator()validates the entire model's data.
In FastAPI
FastAPI uses Pydantic models to declare a request body. Invalid data gets a clear error indicating where and what the incorrect data was.
The JSON Schema of the model is part of the generated OpenAPI schema.
See also
Claims
- id: C1 claim: ValidationError on failed parsing. source: S1 evidence: "
ValidationErroris raised when data cannot be successfully parsed into a model instance"
- id: C2 claim: Field validators return the validated value. source: S2 evidence: "returning the validated value"
- id: C3 claim: FastAPI declares bodies with Pydantic. source: S3 evidence: "To declare a request body, you use [Pydantic]"
Sources
- [S1] Models (Pydantic docs). pydantic/pydantic (GitHub). https://github.com/pydantic/pydantic/blob/main/docs/concepts/models.md . License: MIT. Accessed 2026-11-16.
- [S2] Validators (Pydantic docs). pydantic/pydantic (GitHub). https://github.com/pydantic/pydantic/blob/main/docs/concepts/validators.md . License: MIT. Accessed 2026-11-16.
- [S3] Request Body (FastAPI docs). fastapi/fastapi (GitHub). https://github.com/fastapi/fastapi/blob/master/docs/en/docs/tutorial/body.md . License: MIT. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: pydantic/pydantic (GitHub), Models (Pydantic docs), MIT (https://raw.githubusercontent.com/pydantic/pydantic/main/LICENSE). Copyright (c) 2017 to present Pydantic Services Inc. and individual contributors; pydantic/pydantic (GitHub), Validators (Pydantic docs), MIT (https://raw.githubusercontent.com/pydantic/pydantic/main/LICENSE). Copyright (c) 2017 to present Pydantic Services Inc. and individual contributors; fastapi/fastapi (GitHub), Request Body (FastAPI docs), MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright (c) 2018 Sebastián Ramírez. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: pydantic/pydantic (GitHub), Models (Pydantic docs), MIT (https://raw.githubusercontent.com/pydantic/pydantic/main/LICENSE). Copyright (c) 2017 to present Pydantic Services Inc. and individual contributors; pydantic/pydantic (GitHub), Validators (Pydantic docs), MIT (https://raw.githubusercontent.com/pydantic/pydantic/main/LICENSE). Copyright (c) 2017 to present Pydantic Services Inc. and individual contributors; fastapi/fastapi (GitHub), Request Body (FastAPI docs), MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright (c) 2018 Sebastián Ramírez.
Cite this
iinventedlight. 2026. "Pydantic models and validators: model_validate, model_dump and field_validator." iinventedlight Library, iil:note:60a5wh0j, version of 2026-11-16. https://iinventedlight.com/library/notes/pydantic-models-and-validators/. License: CC-BY-4.0.
@misc{iil_note_60a5wh0j,
author = {{iinventedlight}},
title = {{Pydantic models and validators: model\_validate, model\_dump and field\_validator}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/pydantic-models-and-validators/},
note = {Permanent ID iil:note:60a5wh0j. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/pydantic-models-and-validators.md.