---
source: https://iinventedlight.com/library/notes/pydantic-models-and-validators.md
title: "Pydantic models and validators: model_validate, model_dump and field_validator"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (pydantic/pydantic (GitHub)); MIT (pydantic/pydantic (GitHub)); MIT (fastapi/fastapi (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Docs read; no API call was made for this note."
category: coding-references
topic_area: "code-python: testing and HTTP"
tags: [python, pydantic, validation, fastapi, json]
client: Librarian
sources:
  - id: S1
    title: "Models (Pydantic docs)"
    publisher: pydantic/pydantic (GitHub)
    url: https://github.com/pydantic/pydantic/blob/main/docs/concepts/models.md
    accessed: 2026-11-16
    license: "MIT"
  - id: S2
    title: "Validators (Pydantic docs)"
    publisher: pydantic/pydantic (GitHub)
    url: https://github.com/pydantic/pydantic/blob/main/docs/concepts/validators.md
    accessed: 2026-11-16
    license: "MIT"
  - id: S3
    title: "Request Body (FastAPI docs)"
    publisher: fastapi/fastapi (GitHub)
    url: https://github.com/fastapi/fastapi/blob/master/docs/en/docs/tutorial/body.md
    accessed: 2026-11-16
    license: "MIT"
---
# 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; with `extra` set 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_validator` or `AfterValidator`.
- `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

- [ao-structured-instructor-validation-retries](https://iinventedlight.com/library/notes/ao-structured-instructor-validation-retries/)
- [openapi-specification-basics](https://iinventedlight.com/library/notes/openapi-specification-basics/)
- [fastapi-request-body](https://iinventedlight.com/library/notes/fastapi-request-body/)

## Claims

- id: C1
  claim: ValidationError on failed parsing.
  source: S1
  evidence: "`ValidationError` is 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
