Pydantic AI
Official agent framework from the Pydantic team. Type-safe, model-agnostic. Built by the same team behind pydantic validation used in OpenAI SDK, LangChain, Anthropic SDK. Released November 2024. Reached V1 in September 2025 with API stability commitment. Current version is 1.70.0 (Mar 2026). V2 planned no earlier than April 2026.
Warnings
- breaking result.data was removed. Use result.output. Affects all code written against 0.x docs and tutorials.
- breaking result_type= parameter on Agent() was removed. Use output_type= instead.
- breaking result_retries= parameter removed. Use output_retries= instead.
- breaking Agent.result_validator decorator removed. Use @agent.output_validator instead.
- breaking Agent.last_run_messages property removed. Access messages via RunResult.
- gotcha pydantic v1 is not supported. pydantic-ai requires pydantic v2. Will silently fail or raise confusing errors if pydantic v1 is installed.
- gotcha Model strings use provider:model-name format. 'openai:gpt-4o', 'anthropic:claude-sonnet-4-5', 'google-gla:gemini-2.5-flash'. Wrong format raises UnknownModelError.
- gotcha Before V1 (< 1.0.0), minor versions introduced breaking changes without deprecation warnings. Any code from tutorials written before September 2025 may be broken.
- gotcha run_sync() is a convenience wrapper. In async contexts use await agent.run() instead. Calling run_sync() inside an existing event loop raises RuntimeError.
Install
-
pip install pydantic-ai -
pip install 'pydantic-ai[logfire]' -
pip install 'pydantic-ai[openai]'
Imports
- Agent
from pydantic_ai import Agent, RunContext
- RunContext
from pydantic_ai import Agent, RunContext @agent.tool async def my_tool(ctx: RunContext[MyDeps]) -> str: return ctx.deps.some_value
Quickstart
from pydantic_ai import Agent
agent = Agent(
'openai:gpt-4o',
system_prompt='You are a helpful assistant.'
)
result = agent.run_sync('What is the capital of France?')
print(result.output) # not result.data