pydantic-ai 2.51.0


pip install pydantic-ai

  Latest version

Released: Sep 25, 2026


Meta
Author: Douwe Maan, David Sanchez, Aditya Vardhan, David Montague, Marcelo Trylesinski, Alex Hall, Samuel Colvin
Requires Python: >=3.10

Classifiers

Development Status
  • 5 - Production/Stable

Framework
  • Pydantic
  • Pydantic :: 2

Intended Audience
  • Developers
  • Information Technology

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3
  • Python :: 3 :: Only
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

Topic
  • Internet
  • Scientific/Engineering :: Artificial Intelligence
  • Software Development :: Libraries :: Python Modules

How Python does AI

CI Coverage PyPI versions license Join Slack

Agents, realtime voice, image generation, embeddings. Every model, every interface, typed end to end.


Pydantic AI is the Python AI SDK: a typed, extensible agent loop with every model a string swap away. The same agent runs everywhere you need it: behind a web frontend, in the terminal, on a voice call, on a durable background queue, in GitHub Actions, or as a plain object you call run() on. Image generation and embeddings come in the same box; Pydantic Graph and Pydantic Evals are separate packages, for typed control flow and for testing agent behavior the way pytest tests code.

Pydantic AI Harness has everything an agent needs for complex, long-running work, snapped on as capabilities, from memory, guardrails, and sub-agents to planning, context management, and persistence, up to a complete coding agent.

Pydantic Logfire is the AI observability platform that sees your whole app, not just the LLM calls, and the Pydantic AI Gateway is one key for every model with real-time cost monitoring and budget control; the Gateway self-hosts if you would rather, and our instrumentation is plain OpenTelemetry, so any backend you already run works. Underneath both, genai-prices keeps model pricing current, and Monty is the sandboxed Python interpreter that runs model-written code.

View the complete documentation at pydantic.dev/docs/ai.

What are you building?

From simple typed data extraction to complex, long-running multi-agent collaboration, Pydantic AI and Pydantic AI Harness have got you covered.

Coding agent

A complete coding agent in your terminal: workspace-rooted file access, allowlisted shell, repo orientation, planning, and context management that survives long sessions. Here with web search and a second-opinion advisor snapped on alongside:

uv add pydantic-ai pydantic-ai-harness
from pydantic_ai import Agent
from pydantic_ai.capabilities import WebSearch
from pydantic_ai_harness import Advisor, Coder

agent = Agent(
    'anthropic:claude-fable-5',
    capabilities=[
        Coder(),  # files, shell, repo context, sub-agents, context management
        WebSearch(),  # look up docs and error messages on the web
        Advisor('openai:gpt-5.6-sol'),  # a second opinion from another model when stuck
    ],
)
agent.to_cli_sync()

Coder is a regular combined capability, not a black box: use it whole, or use the blocks it bundles directly; the two are equivalent:

capabilities = [
    FileSystem('.'), Shell(cwd='.'), RepoContext(), SubAgents(...),
    ClearToolResults(), WarnNearLimits(), ToolOutputLimits(), RepairToolArguments(),
]

Run the file and you're chatting with the agent in your terminal. To try it before writing any code, run the exported coder_agent with clai (the Pydantic AI CLI), via uvx:

uvx --with pydantic-ai-harness clai -a pydantic_ai_harness.coder:coder_agent -m anthropic:claude-fable-5

Build this → Coder, from the Harness

Run it on GitHub → GitHub Agentic Workflows, on issues, pull requests or a schedule

Data extraction

Give the agent an output type and tools, and every run comes back validated and typed:

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-5.6-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

The @agent.tool function receives a RunContext that carries your dependencies in; the rest of its signature and its docstring become the tool schema, arguments are validated before your code runs, and the run is guaranteed to return a Sentiment, so your IDE, type checker, and the LLM all agree on the returned type.

Build this → Agents, Function Tools, and Structured Output

Durable workflow

Attach TemporalDurability and the same agent runs inside a Temporal workflow under durable execution: every model and tool call becomes a durable activity, so a run working through a background queue survives restarts, failures, and long waits:

uv add "pydantic-ai[temporal]"
from temporalio import workflow

from pydantic_ai import Agent
from pydantic_ai.capabilities import WebFetch, WebSearch
from pydantic_ai.durable_exec.temporal import PydanticAIWorkflow, TemporalDurability

agent = Agent(
    'openai:gpt-5.6-sol',
    instructions='Research the topic and write a structured brief.',
    name='researcher',
    capabilities=[WebSearch(), WebFetch(), TemporalDurability()],
)


@workflow.defn
class ResearchWorkflow(PydanticAIWorkflow):
    __pydantic_ai_agents__ = [agent]

    @workflow.run
    async def run(self, topic: str) -> str:
        result = await agent.run(f'Write a brief on: {topic}')
        return result.output

DBOS and Prefect attach the same way, first-party and co-maintained, with Restate, AWS Lambda, Kitaru, and Airflow integrations besides.

Build this → Durable Execution

Realtime voice

Put the same agent on a live voice session, tools and capabilities included:

uv add "pydantic-ai[openai-realtime]"
import asyncio

from pydantic_ai import Agent
from pydantic_ai.capabilities import MCP

agent = Agent(
    instructions='You are a helpful voice assistant.',
    capabilities=[MCP('https://internal.example.com/mcp')],  # capabilities work in voice too
)

@agent.tool_plain
def order_status(order_id: str) -> str:
    """Look up the status of an order."""
    return f'Order {order_id}: shipped, arriving Thursday.'

async with agent.realtime('openai:gpt-realtime-2.1').session() as session:
    microphone = asyncio.create_task(session.send_audio(microphone_chunks()))  # your microphone → the model
    speaker = asyncio.create_task(play_audio(session.stream_audio()))  # model audio → your speaker
    async for part in session.stream_transcripts():
        print(f'{part.speaker}: {part.transcript}')

The model calls your tools mid-conversation while it keeps talking, and every session is instrumented; voice is just another frontend, on OpenAI Realtime, Gemini Live, Azure, and xAI Grok Voice.

Build this → Realtime Voice

Image generation

Generate an image with a dedicated image model, no agent run required:

uv add pydantic-ai
from pathlib import Path

from pydantic_ai import ImageGenerator

generator = ImageGenerator('openai:gpt-image-2')
result = generator.generate_sync('A minimalist logo for a coffee shop called Extract.')
Path('logo.png').write_bytes(result.image.data)

That standalone image API is for when your application decides; when an agent run decides, there is provider-native generation with output_type=BinaryImage for a typed image output, and the ImageGeneration capability with its fallbacks for models that generate no images of their own.

Build this → Image Generation

Why Pydantic AI

Built by the Pydantic team: Pydantic Validation is the validation layer of the OpenAI SDK, the Anthropic SDK, the Google ADK, LangChain, and most of the AI ecosystem (and the foundation FastAPI was built on). Pydantic AI brings that same feeling to agents.

Putting it together: a bank support agent

A typed support agent showing several features working together: dependency injection, function tools, structured output, a reusable capability bundling the customer context, and an on-demand capability the model loads only when the conversation calls for it:

from dataclasses import dataclass

from pydantic import BaseModel, Field

from pydantic_ai import Agent, Capability, RunContext

from bank_database import DatabaseConn


@dataclass
class SupportDependencies:  # inject any client: DB pools, HTTP APIs, user info
    customer_id: int
    db: DatabaseConn


class SupportOutput(BaseModel):
    support_advice: str = Field(description='Advice returned to the customer')
    block_card: bool = Field(description="Whether to block the customer's card")
    risk: int = Field(description='Risk level of query', ge=0, le=10)


customer_context = Capability[SupportDependencies](  # a reusable unit of tools + instructions
    id='customer-context',
    description="Who the customer is and what's on their account.",
)


@customer_context.instructions
async def add_customer_name(ctx: RunContext[SupportDependencies]) -> str:
    customer_name = await ctx.deps.db.customer_name(id=ctx.deps.customer_id)
    return f"The customer's name is {customer_name!r}"


@customer_context.tool  # signature and docstring become the tool schema the LLM sees
async def customer_balance(
    ctx: RunContext[SupportDependencies], include_pending: bool
) -> float:
    """Returns the customer's current account balance."""
    return await ctx.deps.db.customer_balance(
        id=ctx.deps.customer_id,
        include_pending=include_pending,
    )


refunds = Capability[SupportDependencies](  # deferred: loads on demand, like a skill
    id='refunds',
    description='Refund eligibility and refund status.',
    defer_loading=True,
)


@refunds.tool
async def refund_status(ctx: RunContext[SupportDependencies]) -> str:
    """Look up the refund status for the customer's most recent charge."""
    return await ctx.deps.db.refund_status(id=ctx.deps.customer_id)


support_agent = Agent(
    'openai:gpt-5.6-sol',
    deps_type=SupportDependencies,
    output_type=SupportOutput,  # the run returns a validated SupportOutput, typed as such
    instructions=(
        'You are a support agent in our bank, give the '
        'customer support and judge the risk level of their query.'
    ),
    capabilities=[customer_context, refunds],
)


...  # in a real use case: more tools, longer instructions


async def main():
    deps = SupportDependencies(customer_id=123, db=DatabaseConn())
    result = await support_agent.run('What is my balance?', deps=deps)
    print(result.output)
    """
    support_advice='Hello John, your current account balance, including pending transactions, is $123.45.' block_card=False risk=1
    """

    result = await support_agent.run('I just lost my card!', deps=deps)
    print(result.output)
    """
    support_advice="I'm sorry to hear that, John. We are temporarily blocking your card to prevent unauthorized transactions." block_card=True risk=8
    """

    result = await support_agent.run(  # the model loads `refunds` on demand, then answers
        'Was I refunded for the duplicate charge on my last statement?', deps=deps
    )
    print(result.output)
    """
    support_advice='Good news, John: the duplicate charge on your last statement was refunded on 2026-05-01.' block_card=False risk=1
    """

For the annotated walkthrough and Logfire tracing, see the same example in the docs.

Next Steps

Part of the Pydantic Stack

Everything you need to ship production-grade AI agents:

2.51.0 Sep 25, 2026
2.50.0 Sep 25, 2026
2.49.0 Sep 24, 2026
2.48.0 Sep 23, 2026
2.47.0 Sep 22, 2026
2.46.0 Sep 19, 2026
2.45.0 Sep 18, 2026
2.44.0 Sep 17, 2026
2.43.0 Sep 12, 2026
2.42.0 Sep 09, 2026
2.41.0 Sep 08, 2026
2.40.0 Sep 05, 2026
2.39.0 Sep 04, 2026
2.38.0 Sep 03, 2026
2.37.0 Sep 01, 2026
2.36.0 Aug 29, 2026
2.35.3 Aug 28, 2026
2.35.1 Aug 27, 2026
2.35.0 Aug 26, 2026
2.34.0 Aug 25, 2026
2.33.0 Aug 21, 2026
2.32.2 Aug 21, 2026
2.32.1 Aug 20, 2026
2.32.0 Aug 19, 2026
2.31.1 Aug 18, 2026
2.31.0 Aug 15, 2026
2.30.0 Aug 14, 2026
2.29.0 Aug 13, 2026
2.28.0 Aug 12, 2026
2.27.1 Aug 11, 2026
2.27.0 Aug 08, 2026
2.26.0 Aug 07, 2026
2.25.0 Aug 06, 2026
2.24.0 Aug 05, 2026
2.23.0 Aug 04, 2026
2.22.0 Aug 01, 2026
2.21.0 Jul 30, 2026
2.20.0 Jul 29, 2026
2.19.0 Jul 28, 2026
2.18.0 Jul 25, 2026
2.17.0 Jul 24, 2026
2.16.0 Jul 23, 2026
2.15.0 Jul 22, 2026
2.14.1 Jul 21, 2026
2.14.0 Jul 21, 2026
2.13.0 Jul 18, 2026
2.12.0 Jul 17, 2026
2.11.0 Jul 16, 2026
2.10.0 Jul 15, 2026
2.9.1 Jul 14, 2026
2.9.0 Jul 11, 2026
2.8.0 Jul 10, 2026
2.7.0 Jul 09, 2026
2.6.0 Jul 08, 2026
2.5.1 Jul 07, 2026
2.5.0 Jul 04, 2026
2.4.0 Jul 03, 2026
2.3.0 Jul 02, 2026
2.2.0 Jul 01, 2026
2.1.0 Jun 29, 2026
2.0.0 Jun 23, 2026
2.0.0b7 Jun 10, 2026
2.0.0b6 Jun 05, 2026
2.0.0b5 Jun 02, 2026
2.0.0b4 May 29, 2026
2.0.0b3 May 23, 2026
2.0.0b2 May 22, 2026
2.0.0b1 May 21, 2026
1.107.6 Sep 17, 2026
1.107.5 Aug 14, 2026
1.107.4 Aug 12, 2026
1.107.2 Aug 08, 2026
1.107.1 Jul 11, 2026
1.107.0 Jun 10, 2026
1.106.0 Jun 05, 2026
1.105.0 Jun 02, 2026
1.104.0 May 29, 2026
1.103.0 May 27, 2026
1.102.0 May 23, 2026
1.101.0 May 22, 2026
1.100.0 May 21, 2026
1.99.0 May 20, 2026
1.98.0 May 19, 2026
1.97.0 May 15, 2026
1.96.1 May 15, 2026
1.96.0 May 14, 2026
1.95.1 May 13, 2026
1.95.0 May 13, 2026
1.94.0 May 12, 2026
1.93.0 May 09, 2026
1.92.0 May 08, 2026
1.91.0 May 07, 2026
1.90.0 May 05, 2026
1.89.1 May 01, 2026
1.89.0 May 01, 2026
1.88.0 Apr 29, 2026
1.87.0 Apr 25, 2026
1.86.1 Apr 24, 2026
1.86.0 Apr 23, 2026
1.85.1 Apr 22, 2026
1.85.0 Apr 21, 2026
1.84.1 Apr 18, 2026
1.84.0 Apr 17, 2026
1.83.0 Apr 16, 2026
1.82.0 Apr 15, 2026
1.81.0 Apr 14, 2026
1.80.0 Apr 10, 2026
1.79.0 Apr 10, 2026
1.78.0 Apr 08, 2026
1.77.0 Apr 03, 2026
1.76.0 Apr 02, 2026
1.75.0 Apr 01, 2026
1.74.0 Mar 31, 2026
1.73.0 Mar 27, 2026
1.72.0 Mar 26, 2026
1.71.0 Mar 24, 2026
1.70.0 Mar 18, 2026
1.69.0 Mar 17, 2026
1.68.0 Mar 13, 2026
1.67.0 Mar 06, 2026
1.66.0 Mar 05, 2026
1.65.0 Mar 03, 2026
1.64.0 Mar 02, 2026
1.63.0 Feb 23, 2026
1.62.0 Feb 19, 2026
1.61.0 Feb 18, 2026
1.60.0 Feb 17, 2026
1.59.0 Feb 14, 2026
1.58.0 Feb 11, 2026
1.57.0 Feb 10, 2026
1.56.0 Feb 06, 2026
1.55.0 Feb 05, 2026
1.54.0 Feb 04, 2026
1.53.0 Feb 04, 2026
1.52.0 Feb 03, 2026
1.51.0 Jan 31, 2026
1.50.0 Jan 30, 2026
1.49.0 Jan 29, 2026
1.48.0 Jan 28, 2026
1.47.0 Jan 24, 2026
1.46.0 Jan 23, 2026
1.44.0 Jan 17, 2026
1.43.0 Jan 16, 2026
1.42.0 Jan 14, 2026
1.41.0 Jan 10, 2026
1.40.0 Jan 07, 2026
1.39.1 Jan 06, 2026
1.39.0 Dec 24, 2025
1.38.0 Dec 23, 2025
1.37.0 Dec 20, 2025
1.36.0 Dec 19, 2025
1.35.0 Dec 18, 2025
1.34.0 Dec 17, 2025
1.33.0 Dec 16, 2025
1.32.0 Dec 13, 2025
1.31.0 Dec 12, 2025
1.30.1 Dec 11, 2025
1.30.0 Dec 11, 2025
1.29.0 Dec 10, 2025
1.28.0 Dec 09, 2025
1.27.0 Dec 05, 2025
1.26.0 Dec 03, 2025
1.25.1 Nov 28, 2025
1.25.0 Nov 28, 2025
1.24.0 Nov 27, 2025
1.23.0 Nov 26, 2025
1.22.0 Nov 22, 2025
1.21.0 Nov 21, 2025
1.20.0 Nov 19, 2025
1.19.0 Nov 18, 2025
1.18.0 Nov 15, 2025
1.17.0 Nov 14, 2025
1.16.0 Nov 13, 2025
1.15.0 Nov 13, 2025
1.14.1 Nov 12, 2025
1.14.0 Nov 10, 2025
1.13.0 Nov 10, 2025
1.12.0 Nov 07, 2025
1.11.1 Nov 06, 2025
1.11.0 Nov 05, 2025
1.10.0 Nov 04, 2025
1.9.1 Oct 31, 2025
1.9.0 Oct 29, 2025
1.8.0 Oct 29, 2025
1.7.0 Oct 28, 2025
1.6.0 Oct 24, 2025
1.5.0 Oct 24, 2025
1.4.0 Oct 24, 2025
1.3.0 Oct 23, 2025
1.2.1 Oct 20, 2025
1.2.0 Oct 20, 2025
1.1.0 Oct 15, 2025
1.0.18 Oct 13, 2025
1.0.17 Oct 09, 2025
1.0.16 Oct 08, 2025
1.0.15 Oct 03, 2025
1.0.14 Oct 03, 2025
1.0.13 Oct 02, 2025
1.0.12 Oct 01, 2025
1.0.11 Sep 30, 2025
1.0.10 Sep 20, 2025
1.0.9 Sep 18, 2025
1.0.8 Sep 17, 2025
1.0.7 Sep 15, 2025
1.0.6 Sep 12, 2025
1.0.5 Sep 12, 2025
1.0.4 Sep 11, 2025
1.0.3 Sep 11, 2025
1.0.2 Sep 09, 2025
1.0.1 Sep 05, 2025
1.0.0 Sep 05, 2025
1.0.0b1 Aug 30, 2025
0.8.1 Aug 29, 2025
0.8.0 Aug 26, 2025
0.7.6 Aug 26, 2025
0.7.5 Aug 25, 2025
0.7.4 Aug 20, 2025
0.7.3 Aug 19, 2025
0.7.2 Aug 14, 2025
0.7.1 Aug 13, 2025
0.7.0 Aug 12, 2025
0.6.2 Aug 07, 2025
0.6.1 Aug 07, 2025
0.6.0 Aug 06, 2025
0.5.1 Aug 06, 2025
0.5.0 Aug 04, 2025
0.4.11 Aug 02, 2025
0.4.10 Jul 30, 2025
0.4.9 Jul 28, 2025
0.4.8 Jul 28, 2025
0.4.7 Jul 24, 2025
0.4.6 Jul 23, 2025
0.4.5 Jul 22, 2025
0.4.4 Jul 18, 2025
0.4.3 Jul 16, 2025
0.4.2 Jul 10, 2025
0.4.1 Jul 10, 2025
0.4.0 Jul 08, 2025
0.3.7 Jul 07, 2025
0.3.6 Jul 04, 2025
0.3.5 Jun 30, 2025
0.3.4 Jun 26, 2025
0.3.3 Jun 24, 2025
0.3.2 Jun 21, 2025
0.3.1 Jun 18, 2025
0.3.0 Jun 18, 2025
0.2.20 Jun 18, 2025
0.2.19 Jun 17, 2025
0.2.18 Jun 13, 2025
0.2.17 Jun 12, 2025
0.2.16 Jun 08, 2025
0.2.15 Jun 05, 2025
0.2.14 Jun 03, 2025
0.2.13 Jun 03, 2025
0.2.12 May 29, 2025
0.2.11 May 28, 2025
0.2.10 May 27, 2025
0.2.9 May 26, 2025
0.2.8 May 25, 2025
0.2.7 May 24, 2025
0.2.6 May 21, 2025
0.2.5 May 20, 2025
0.2.4 May 14, 2025
0.2.3 May 13, 2025
0.2.2 May 13, 2025
0.2.1 May 13, 2025
0.2.0 May 12, 2025
0.1.12 May 12, 2025
0.1.11 May 10, 2025
0.1.10 May 06, 2025
0.1.9 May 02, 2025
0.1.8 Apr 28, 2025
0.1.7 Apr 28, 2025
0.1.6 Apr 25, 2025
0.1.5 Apr 25, 2025
0.1.4 Apr 24, 2025
0.1.3 Apr 18, 2025
0.1.2 Apr 17, 2025
0.1.1 Apr 16, 2025
0.1.0 Apr 15, 2025
0.0.55 Apr 09, 2025
0.0.54 Apr 09, 2025
0.0.53 Apr 07, 2025
0.0.52 Apr 03, 2025
0.0.51 Apr 03, 2025
0.0.50 Apr 03, 2025
0.0.49 Apr 01, 2025
0.0.48 Mar 31, 2025
0.0.47 Mar 31, 2025
0.0.46 Mar 26, 2025
0.0.45 Mar 26, 2025
0.0.44 Mar 25, 2025
0.0.43 Mar 21, 2025
0.0.42 Mar 19, 2025
0.0.41 Mar 17, 2025
0.0.40 Mar 15, 2025
0.0.39 Mar 13, 2025
0.0.38 Mar 13, 2025
0.0.37 Mar 12, 2025
0.0.36 Mar 07, 2025
0.0.35 Mar 05, 2025
0.0.34 Mar 05, 2025
0.0.33 Mar 05, 2025
0.0.32 Mar 04, 2025
0.0.31 Mar 03, 2025
0.0.30 Feb 28, 2025
0.0.29 Feb 27, 2025
0.0.28 Feb 27, 2025
0.0.27 Feb 26, 2025
0.0.26 Feb 25, 2025
0.0.25 Feb 24, 2025
0.0.24 Feb 12, 2025
0.0.23 Feb 07, 2025
0.0.22 Feb 04, 2025
0.0.21 Jan 30, 2025
0.0.20 Jan 24, 2025
0.0.19 Jan 15, 2025
0.0.18 Jan 07, 2025
0.0.17 Jan 03, 2025
0.0.16 Dec 30, 2024
0.0.15 Dec 23, 2024
0.0.14 Dec 19, 2024
0.0.13 Dec 16, 2024
0.0.12 Dec 09, 2024
0.0.11 Dec 06, 2024
0.0.10 Dec 06, 2024
0.0.9 Dec 04, 2024
0.0.8 Dec 02, 2024
0.0.7 Nov 29, 2024
0.0.6 Nov 25, 2024
0.0.6a4 Nov 25, 2024
0.0.6a3 Nov 25, 2024
0.0.6a2 Nov 25, 2024
0.0.6a1 Nov 25, 2024
0.0.5 Nov 20, 2024
0.0.4 Nov 19, 2024
0.0.3 Nov 19, 2024
0.0.2 Oct 30, 2024
0.0.1 Oct 29, 2024
0.0.0 May 20, 2024

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
pydantic-ai-slim[cli,web,logfire,google,mcp,anthropic,openai,evals] (==2.51.0)