Core Concepts
Key features that make Pydantic AI a robust choice for enterprise applications.
Type Validation
Agent inputs, outputs, and system tools are strictly defined using Pydantic schemas, raising validation errors immediately if models return invalid formats.
Dynamic Prompts
Inject prompts dynamically based on runtime context using `@agent.system_prompt`, allowing agent behaviors to adapt to authenticated user roles or state databases.
Structured Streaming
Stream agent responses in real time. Supports streaming plain text or structured Pydantic objects as they are built chunk-by-chunk by the model.
Dependency Injection
Provide external dependencies (like active database clients, search engines, or API keys) dynamically to tools based on conversation contexts.
Conversation Memory
Persist and pass multi-turn chat history objects directly inside execution calls, allowing the agent to remember context across API thresholds.
Model Agnostic
Supports OpenAI, Anthropic, Gemini, or open-weights local models (via Ollama) with a single unified tool-calling interface.
Setup & Installation
Get started building with Pydantic AI in your Python environment.
Install Framework Package
Production Agent Example
Defining schemas, injecting dynamic prompts, streaming text completions, and managing conversation history.