What it is
Pydantic AI is the Python agent framework from the Pydantic team, built around the most annoying part of putting a model into production code: a model output is fundamentally unconstrained text, while the code downstream needs a definite structure. It brings Pydantic validation straight to the model call. You describe the result you want with a data class, and the framework parses, validates and retries the response, raising rather than letting malformed data flow downstream. The framework is model agnostic, covering OpenAI, Anthropic, Gemini, Grok, Bedrock, Mistral, Cohere and local Ollama, and switching usually means changing one line. Beyond structured results, tool calling, dependency injection, system prompts, streaming, multi-turn history and usage accounting are all first-class. It supports MCP and A2A, and can plug into DBOS or Temporal for durable execution so a long run resumes from where it stopped. On debugging it integrates deeply with Logfire, its sibling project, so a run’s full trace, prompts, tool arguments and token spend can be reviewed after the fact. Testing and evaluation are treated as part of the framework too, with official patterns for asserting agent behaviour in pytest and evaluation tools that score one model’s output against a rubric. As of October 2026 the repository has roughly 20,000 stars, is primarily Python and is licensed under MIT.
Highlights
- Structured output binds to a Pydantic model, with automatic retries and validation errors on parse failure
- Model agnostic, so switching between OpenAI, Anthropic, Gemini or local Ollama is usually a one-line change
- Dependency injection gives system prompts and tools request-level context, and makes them easy to swap in tests
- Logfire integration exposes prompts, tool arguments, traces and token spend step by step
- MCP and A2A support, plus DBOS or Temporal for durable execution that survives interruption
- Official pytest patterns and evaluation tooling mean agent behaviour can be tested like ordinary code
- MIT licensed with no additional restrictions on commercial use or redistribution
How to use
Install with pip install pydantic-ai or uv add pydantic-ai, define a result type extending BaseModel, create the Agent with a model name, the result type and a system prompt, then call it with run_sync or run. Tools are plain functions whose parameter types the framework turns into a JSON Schema for the model. Write the result type strictly from the start: concrete types, constraints, complete enums. The uncertainty in model output gets stopped at that boundary, and everything downstream stops needing defensive checks.
License
Released under MIT. Read the terms before commercial use or redistribution, especially if you plan to offer it as a service.