PydanticAI
Agent framework from the Pydantic team. Define agents with typed tools and structured outputs, tested with testable dependency injection and model-agnostic design.
Install
$pip install pydantic-ai About
PydanticAI applies Pydantic's philosophy — "validate at the boundary" — to LLM applications. Agents have explicitly typed result types; if the model returns something that doesn't match, Pydantic retries with the validation error as feedback.
Dependency injection is the standout feature for testing. Instead of mocking HTTP calls to the model API, you swap in a TestModel that returns deterministic responses, making unit tests fast and reliable.
Getting Started
pip install pydantic-ai
from pydantic import BaseModel
from pydantic_ai import Agent
class CityInfo(BaseModel):
city: str
country: str
population: int
agent = Agent("anthropic:claude-sonnet-4-5", result_type=CityInfo)
result = agent.run_sync("What is the capital of Japan?")
print(result.data)Features
References & Links
Project Info
Topics
Ready to try PydanticAI?
Free and open source. Install in one command, works with Claude Code, Cursor, Windsurf, and more.
$pip install pydantic-ai