Agent runtime

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.

Operating principle

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