Core Concepts
Reasoning
Memory & Retrieval
Agent Types
Design Patterns
Training & Alignment
Frameworks
Tools
Safety & Security
Evaluation
Meta
Core Concepts
Reasoning
Memory & Retrieval
Agent Types
Design Patterns
Training & Alignment
Frameworks
Tools
Safety & Security
Evaluation
Meta
This is an old revision of the document!
PydanticAI is a type-safe Python agent framework built by the creators of Pydantic. With 15.7K GitHub stars and 390+ contributors, it brings the “FastAPI feeling” to GenAI development — validated outputs, dependency injection, structured tool contracts, and observability as first-class concerns rather than afterthoughts.
framework python type-safe agents pydantic dependency-injection
PydanticAI was created by the Pydantic team (Samuel Colvin et al.) after they found that despite virtually every Python AI framework using Pydantic for validation, none provided the ergonomic developer experience that FastAPI brought to web development. Released in mid-2024, PydanticAI v1.0 shipped in September 2025 and has rapidly iterated to v1.70+ by March 2026. The framework validates agent inputs, outputs, tool parameters, and dependency types at every boundary using Pydantic models, surfacing errors at development time rather than in production.
PydanticAI follows a clean, layered architecture centered on type-safe boundaries:
┌──────────────────────────────────────────────┐
│ Agent[Deps, Output] │
│ ┌────────────┐ ┌───────────┐ ┌───────────┐ │
│ │Instructions│ │ Tools │ │ Output │ │
│ │ (system │ │(validated │ │ Schema │ │
│ │ prompt) │ │ functions)│ │(Pydantic) │ │
│ └────────────┘ └───────────┘ └───────────┘ │
└──────────────────┬───────────────────────────┘
│
┌──────────────────▼───────────────────────────┐
│ Model Interface Layer │
│ OpenAI | Anthropic | Gemini | Ollama | ... │
└──────────────────┬───────────────────────────┘
│
┌──────────────────▼───────────────────────────┐
│ Observability (Logfire) │
│ Traces | Spans | Metrics | OpenTelemetry │
└──────────────────────────────────────────────┘
A type-safe agent with dependency injection and structured output:
from pydantic import BaseModel from pydantic_ai import Agent class CityInfo(BaseModel): name: str country: str population: int known_for: list[str] # Create a type-safe agent with structured output agent = Agent( "openai:gpt-4o", output_type=CityInfo, system_prompt="You are a geography expert. Return accurate city data.", ) # Run the agent — output is validated against CityInfo schema result = agent.run_sync("Tell me about Paris") print(f"City: {result.output.name}") print(f"Country: {result.output.country}") print(f"Population: {result.output.population:,}") print(f"Known for: {', '.join(result.output.known_for)}") # Type-safe tool with dependency injection from dataclasses import dataclass @dataclass class WeatherDeps: api_key: str weather_agent = Agent( "openai:gpt-4o", deps_type=WeatherDeps, system_prompt="Use the weather tool to answer questions.", ) @weather_agent.tool async def get_weather(ctx, city: str) -> str: api_key = ctx.deps.api_key # Type-safe access return f"Weather in {city}: 22C, sunny"
The PydanticAI ecosystem consists of focused packages:
| Package | Purpose |
|---|---|
| pydantic-ai | Core agent framework with tools and DI |
| pydantic-ai-slim | Minimal install without provider extras |
| pydantic-graph | Graph-based multi-step workflows |
| pydantic-evals | Agent evaluation and testing framework |