Pydantic AI
A type-safe Python agent framework built by the Pydantic team
Repository Health
Technical Analysis
Pydantic AI is a Python framework for building production-grade Generative AI applications and agents, built by the team behind Pydantic Validation. It aims to bring the ergonomic, type-safe developer experience of FastAPI to agent development, with model-agnostic support for OpenAI, Anthropic, Gemini, Bedrock, Ollama, and dozens of other providers.
The framework provides structured/validated output, dependency injection for tools, durable execution across transient failures, human-in-the-loop tool approval, streamed structured outputs, and a graph-based control-flow system, plus first-class integration with Pydantic Logfire for OpenTelemetry observability. The published pydantic-ai package is a thin wrapper that re-exports pydantic-ai-slim (the actual implementation, with optional extras per model provider).
What You Get
- Model-agnostic
AgentAPI supporting OpenAI, Anthropic, Gemini, Bedrock, Ollama, and more - Pydantic-validated, type-safe structured output from LLM responses
- Dependency injection for tools via a typed
RunContext - Model Context Protocol (MCP) client/server support for external tool access
- Durable execution helpers for surviving transient failures in long-running agent workflows
- A
pydantic_graphmodule for defining complex multi-step agent control flow with type hints - Built-in OpenTelemetry instrumentation with first-class Pydantic Logfire integration
- A
pydantic_evalspackage for systematically evaluating agent performance and accuracy
Common Use Cases
- Building a customer support agent that calls internal tools and returns validated structured responses
- Creating a multi-step agentic workflow using pydantic_graph for complex branching logic
- Adding human-in-the-loop approval gates before an agent executes sensitive tool calls
- Streaming structured output from an LLM to a frontend as it’s generated
- Evaluating and regression-testing agent behavior across model or prompt changes with pydantic_evals
- Connecting an agent to external data/tools via MCP servers
Under The Hood
Architecture - The pydantic_ai_slim/pydantic_ai package centers on agent/ (the Agent class and run loop), _agent_graph.py (the internal step-by-step execution graph an agent run traverses), models/ (per-provider adapters normalizing requests/responses), tools.py/tool_manager.py/toolsets/ (tool registration, schema generation, and dependency injection via RunContext), mcp.py (Model Context Protocol client integration), and durable_exec/ (checkpointing/resumption for long-running workflows); the sibling pydantic_graph package provides a standalone typed state-machine/graph library that pydantic_ai builds its agent run loop on top of, and pydantic_evals provides a separate evaluation harness.
Tech Stack - Modern Python (using hatchling + uv-dynamic-versioning for builds, uv for dependency management), built directly on Pydantic Validation for schema/output validation, with per-provider optional extras (e.g. pydantic-ai-slim[openai]) so users only install the model SDKs they need, and OpenTelemetry for tracing baked in at the core rather than bolted on.
Code Quality - An extensive tests/ tree (models, providers, graph, evals, v2, cassette-based HTTP recordings for deterministic provider tests) reflects heavy investment in test coverage for a fast-moving library (167 commits/month, 100 releases to date); py.typed marker and consistent type hints throughout pydantic_ai_slim/pydantic_ai support the framework’s stated ‘fully type-safe’ goal, and CI badges show coverage tracking is actively enforced.
API Design - The core mental model is small - define an Agent with a model and an output type, decorate functions as @agent.tool to register them, and call .run() - while advanced capabilities (MCP, durable execution, human-in-the-loop approval, graphs) are opt-in layers rather than required upfront complexity, closely mirroring the progressive-disclosure design philosophy of FastAPI that the framework explicitly cites as its inspiration.
Used by 15 apps in this directory
Polar
Developer Tools · Ecommerce · Invoicing Finance
Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.
Promptfoo
AI Development
An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.
Stirling PDF
Digital Signiture · Productivity
The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.
Stirling PDF
Digital Signiture · Productivity
The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.
Tracecat
AI Agents · Automation · Security
Open-source agentic security automation platform that runs AI agents and durable workflows at scale with sandboxed execution.
WrenAI
AI Agents · Analytics · Data Engineering
Open-source GenBI engine that lets AI agents turn natural-language questions into governed SQL, charts, and shareable dashboards across 20+ data sources — no vendor lock-in, no black-box prompts.