TOOL WIKI · AGENT SDKS

Pydantic AI

Combines Python agent construction with typed dependencies and structured outputs.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Return a typed status from an agent

A developer needs a small, observable agent or retrieval step before connecting real business services.

Input
OrderAnswer schema, order_status tool and the A104 question.
Expected output
A validated order_id/status object based on the fixture.
  • Success check: The returned object validates against OrderAnswer and reports packed.
  • Try a failure: An invented status must be rejected by the output contract and grounding checks.

Example scope: Actual model-backed typed agent; schema validation alone does not establish factual correctness.

Official reference · Pydantic AI

WHAT IT ISAgent framework
WHERE IT FITSAgent SDKs
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
taskinvokedecisiontool callresultstatemeasureApplicationTask + identityPydantic AIAgent frameworkModel providerConfigured API modelTool serviceAuthorization + executionState storageRun and thread progressEvaluationOutcome + evidence
  1. Authenticate the request and define the goal before calling the framework.

  2. Applications where validated data contracts are central to the agent. Schema validity is separate from factual correctness.

  3. The application supplies provider credentials, model selection, and budgets.

  4. Validate each operation and return authoritative observations.

  5. Choose the checkpoint or session store and its retention policy deliberately.

    Result or stopping point
  6. Check completion, cost, latency, and tool behavior against fixtures.

    Result or stopping point
Pydantic AI

Applications where validated data contracts are central to the agent. Schema validity is separate from factual correctness.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

When to consider it

  • Applications where validated data contracts are central to the agent.

A design decision to make

  • Schema validity is separate from factual correctness.

Prerequisites and setup

  • Python 3.11+ in an empty directory. A compatible model and provider credentials are required.
  • Running the model-backed example can incur API charges; this website displays it without calling a provider.
Shell
python3 -m venv .venv
source .venv/bin/activate
pip install pydantic-ai
export OPENAI_API_KEY="YOUR_API_KEY"
export OPENAI_MODEL="YOUR_ENABLED_MODEL"

Try a small integration

example.py

Python · example.py
import os
from pydantic import BaseModel
from typing import Literal
from pydantic_ai import Agent

class OrderAnswer(BaseModel):
    order_id: str
    status: Literal["packed", "not_found"]

agent = Agent("openai:"+os.environ["OPENAI_MODEL"], output_type=OrderAnswer,
    instructions="Always use order_status; preserve not_found exactly.")
@agent.tool_plain
def order_status(order_id: str) -> str:
    """Read the status of one order."""
    return {"A104":"packed"}.get(order_id,"not_found")

result = agent.run_sync("What is the status of A104?")
print(result.output.model_dump())

Run and check the result

Shell
python example.py
  • The returned object validates against OrderAnswer and reports packed.
  • Schema validation checks shape; compare the status with the tool observation to check truth.

Common failures

  • 401 or model-not-found: verify the provider key, project and configured model identifier.
  • A repeated tool call needs a bounded loop and a clear not-found result; do not raise limits blindly.

Production decisions

  • Bind tool execution to the authenticated user and resource permissions. Keep keys in server environment variables.
  • Add deadlines, a turn budget, redacted traces, regression fixtures and explicit handling for refused or incomplete runs.

Keep exploring

Workflow, single agent, or multiple agents?Build an explicit agent loop with LangGraph

Explore the same layer

OpenAI Agents SDKClaude Agent SDKGoogle ADKLangGraph

Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.