pydantic-ai

How Python does AI. Agents, realtime voice, image generation, embeddings. Every model, every interface, typed end to end.

What is pydantic-ai?

How Python does AI. Agents, realtime voice, image generation, embeddings. Every model, every interface, typed end to end.

Overview of pydantic-ai

What it is

Pydantic AI is a Python AI SDK described in its README as "How Python does AI. Agents, realtime voice, image generation, embeddings. Every model, every interface, typed end to end." It provides a typed, extensible agent loop where every model is a string swap away and another can be used as a fallback when a provider fails. The same agent can run behind a web frontend, in the terminal, on a voice call, on a durable background queue, in GitHub Actions, or as a plain object with a run() method. The project is open source under the MIT license.

Key features

  • Typed agent loop with structured output validation via Pydantic models.
  • Model swapping and fallback: every model is a string swap away, with automatic fallback to another model on failure.
  • Realtime voice sessions using OpenAI Realtime, Gemini Live, Azure, and xAI Grok Voice.
  • Image generation with dedicated image models, either standalone or as part of an agent run.
  • Embeddings support included in the same package.
  • Durable execution via integrations with Temporal, DBOS, Prefect, Restate, AWS Lambda, Airflow, and others.
  • Capabilities system (memory, guardrails, sub-agents, planning, context management, persistence) via the separate Pydantic AI Harness package.

Use cases

  • Simple typed data extraction from text.
  • Complex, long-running multi-agent collaboration.
  • Coding agent with file access, shell, repo context, planning, and context management.
  • Durable workflows that survive restarts and failures.
  • Realtime voice assistants with tool calling.
  • Image generation for applications that need to produce visuals.

Getting started

Install the package and run a basic data extraction agent:

uv add pydantic-ai
from typing import Literal
from pydantic import BaseModel, Field
from pydantic_ai import Agent, RunContext

class Sentiment(BaseModel):
    label: Literal['positive', 'negative', 'neutral']
    score: float = Field(ge=-1, le=1)

agent = Agent('openai:gpt-6.1-sol', output_type=Sentiment)

@agent.tool
def recent_reviews(ctx: RunContext, product: str) -> list[str]:
    """Fetch recent review snippets for a product."""
    return ['The new release fixed everything I complained about!']

result = agent.run_sync('How are people feeling about the Extract app?')
print(result.output)
### > label='positive' score=0.9

License and pricing

MIT license, open source.

Based on the project's public README and repository metadata.

Add this badge to your README

Featured on YunoDB Badge styles & help

Maintain this project? Show that it is featured on YunoDB.

Markdown[![Featured on YunoDB](https://yunodb.com/badge/pydanticpydantic-ai.svg)](https://yunodb.com/tools/pydanticpydantic-ai?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/pydanticpydantic-ai?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/pydanticpydantic-ai.svg" alt="Featured on YunoDB" height="20"></a>