Pydantic AI

A type-safe Python agent framework built by the Pydantic team

Framework
PyPI
v2.51.0
20,217 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
91 /100 Excellent
Development Activity 100
Maintenance 100
Community 76
Maturity 48
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
84 /100 Excellent
Architecture 85
Code Quality 86
Innovation 85
Learning Curve 78

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 Agent API 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_graph module for defining complex multi-step agent control flow with type hints
  • Built-in OpenTelemetry instrumentation with first-class Pydantic Logfire integration
  • A pydantic_evals package 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

Python
65%
Apache 2.0

Polar

Developer Tools · Ecommerce · Invoicing Finance

10,293

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
66
Dependency
Built with
Python 65%
TypeScript 28%
Updated 1 weeks ago
TypeScript
97%
MIT

Promptfoo

AI Development

25,506

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.

View details
90
Repo Health
73
Technical
68
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
Java
46%
Other

Stirling PDF

Digital Signiture · Productivity

93,148

The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.

View details
92
Repo Health
86
Technical
71
Dependency
Built with
Java 46%
TypeScript 45%
Updated 1 weeks ago
Java
46%
Other

Stirling PDF

Digital Signiture · Productivity

93,148

The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.

View details
92
Repo Health
86
Technical
71
Dependency
Built with
Java 46%
TypeScript 45%
Updated 1 weeks ago
Python
70%
AGPL 3.0

Tracecat

AI Agents · Automation · Security

3,816

Open-source agentic security automation platform that runs AI agents and durable workflows at scale with sandboxed execution.

View details
89
Repo Health
88
Technical
66
Dependency
Built with
Python 70%
TypeScript 28%
Updated 1 weeks ago
Python
65%
Apache 2.0

WrenAI

AI Agents · Analytics · Data Engineering

17,763

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.

View details
90
Repo Health
91
Technical
69
Dependency
Built with
Python 65%
Rust 32%
Updated 2 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers