Pydantic AI

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

Framework
PyPI
v2.32.0
19,379stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
90/100Excellent
Development Activity100
Maintenance100
Community76
Maturity44
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture85
Code Quality86
Innovation85
Learning Curve78

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 5 apps in this directory

Rust
46%
MIT

Meetily

Productivity · AI Assistants

29,484

Privacy-first AI meeting assistant that transcribes and summarizes your meetings entirely on your local machine — no cloud, no data leakage.

View details
70
Repo Health
72
Technical
71
Dependency
Built with
Rust46%
TypeScript30%
Updated 2 months ago
Python
100%
MIT

Ossature

AI Development

199

An open-source build system that turns written specs and architecture into working code — an LLM generates code under tight constraints, task by task with narrow context windows, instead of attempting an entire codebase at once.

View details
55
Repo Health
70
Technical
83
Dependency
Built with
Python100%
Updated 1 weeks ago
TypeScript
97%
MIT

Promptfoo

AI Development

24,362

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
TypeScript97%
Updated yesterday
Java
48%
Other

Stirling PDF

Productivity · Digital Signiture

89,831

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

View details
90
Repo Health
86
Technical
72
Dependency
Built with
Java48%
TypeScript42%
Updated today
Python
61%
Apache 2.0

WrenAI

Analytics · AI Agents · Data Engineering

17,313

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
91
Repo Health
91
Technical
69
Dependency
Built with
Python61%
Rust36%
Updated today

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

Search