Pydantic
The Python library for defining data schemas as typed models with runtime validation — the layer that turns model output from 'probably JSON' into objects your code can trust.
Production AI is a system: context, tools, permissions, traces, evals, and feedback loops around the model.
What it is
Pydantic lets you declare a schema as a Python class; it validates incoming data against it, coerces types, and reports precise errors. Version 2 runs its core in Rust for speed. It is the de facto standard for data contracts in Python — FastAPI is built on it, most LLM tooling emits or consumes it, and the JSON Schema that tool definitions compile to usually starts life as a Pydantic model.
Why it matters for AI
Everything that passes between a model and your systems is a schema: tool arguments, structured outputs, API payloads. Declaring those once as typed models and enforcing them at runtime is what keeps a generation pipeline from silently accepting malformed data.
How we use it
Every structured output and tool argument in our production stack validates through a Pydantic schema before any system acts on it. Failed validation goes back to the model as a retry carrying the specific error, which corrects most malformed outputs without a human in the loop.
Related resources
Making a model return data in a declared schema — JSON that validates against a Pydantic or Zod model — so downstream code consumes typed fields instead of parsing prose.
The agent framework from the Pydantic team — typed agents, structured outputs, tool calling, retries, and evals built around Pydantic validation, with first-class multi-provider and fallback support.
Every tool an agent uses comes with a precise, versioned form describing exactly what goes in and what comes out — so nothing changes shape quietly and breaks your workflows.
The mechanism by which a language model invokes external functions — APIs, databases, code execution, retrieval — and reads the results back to continue its work.