Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use this skill whenever the user is working with the Pydantic AI framework — including building AI agents, defining structured outputs with Pydantic models, wiring up tools/function calling, configuring model providers (OpenAI, Anthropic, Gemini, etc.), managing dependencies via agent context, handling streaming responses, or debugging agent runs. Trigger this skill even for adjacent tasks like "how do I make my agent return JSON", "set up a multi-step agent", "add a tool to my agent", or "valid
.claude/skills/dougtrajano-pydanticai-docs/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-09 | ✗→✓ | ▲ Improved | -51% | 0% |
| case-10 | ✗→✓ | ▲ Improved | -25% | 0% |
| case-11 | ✗→✓ | ▲ Improved | -29% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 34% | 0% |
| case-02 | ✗→✓ | ▲ Improved | -53% | 0% |
Pydantic AI is a production-grade Python agent framework for building type-safe, dependency-injected Generative AI applications. It supports multiple LLM providers, structured outputs via Pydantic models, and composable multi-agent patterns.
Doc: <https://ai.pydantic.dev/>
pythonfrom pydantic_ai import Agent agent = Agent( 'openai:gpt-4o', # model string: provider:model-name system_prompt='Be helpful.', ) result = agent.run_sync('What is the capital of France?') print(result.output)
For full constructor parameters, run methods, and streaming: load references/AGENT.md.
@agent.tool)pythonfrom pydantic_ai import Agent, RunContext agent = Agent('openai:gpt-4o', deps_type=str) @agent.tool def get_user_name(ctx: RunContext[str]) -> str: """Return the current user's name.""" return ctx.deps result = agent.run_sync('What is my name?', deps='Alice')
Use @agent.tool_plain when you don't need RunContext. For tool registration, return types, and retries: load references/FUNCTION_TOOLS.md.
RunContext)pythonfrom dataclasses import dataclass from pydantic_ai import Agent, RunContext @dataclass class MyDeps: api_key: str user_id: int agent = Agent('openai:gpt-4o', deps_type=MyDeps) @agent.tool async def fetch_data(ctx: RunContext[MyDeps]) -> str: return f'User {ctx.deps.user_id}'
For RunContext fields, injection into system prompts and output validators: load references/DEPENDENCIES.md.
pythonfrom pydantic import BaseModel from pydantic_ai import Agent class CityInfo(BaseModel): city: str country: str agent = Agent('openai:gpt-4o', output_type=CityInfo) result = agent.run_sync('Where were the 2012 Olympics held?') print(result.output) # CityInfo(city='London', country='United Kingdom')
For union types, plain scalars, output_validator, and partial validation: load references/OUTPUT.md.
> For these topics, load the named reference file or follow the doc link — no implementation code is provided here.
| Topic | Reference file | Doc link | |---|---|---| | Message history / multi-turn conversations | references/MESSAGES.md | <https://ai.pydantic.dev/core-concepts/message-history/index.md> | | Model / provider setup (all providers) | references/MODELS.md | <https://ai.pydantic.dev/models/overview/index.md> | | Toolsets (FunctionToolset, composition) | references/TOOLS_AND_TOOLSETS.md | <https://ai.pydantic.dev/tools-toolsets/toolsets/index.md> | | MCP server integration | references/MCP.md | <https://ai.pydantic.dev/mcp/client/index.md> | | Multi-agent applications | doc link only | <https://ai.pydantic.dev/guides/multi-agent-applications/index.md> | | Graphs (pydantic-graph) | doc link only | <https://ai.pydantic.dev/graph/graph/index.md> | | Evals (pydantic-evals) | doc link only | <https://ai.pydantic.dev/evals/evals/index.md> | | Durable execution | doc link only | <https://ai.pydantic.dev/durable_execution/overview/index.md> | | Retries | doc link only | <https://ai.pydantic.dev/core-concepts/retries/index.md> | | Testing (TestModel, override) | doc link only | <https://ai.pydantic.dev/guides/testing/index.md> | | Logfire integration | doc link only | <https://ai.pydantic.dev/integrations/logfire/index.md> | | Native tools (formerly builtin tools) | doc link only | <https://ai.pydantic.dev/tools-toolsets/native-tools/index.md> | | Streaming | doc link only | <https://ai.pydantic.dev/core-concepts/agent/index.md> |
references/<CONCEPT>.md relevant to the user's question when more depth is needed.models/anthropic/index.md) when the user's question targets a specific provider, not the overview.| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-09 | fail→pass | 19,156 | 2,846 | -85% | 1 | 1 | 0% | 3,697 | 1,800 | -51% | 0 | 0 | — |
case-10 | fail→pass | 33,738 | 3,004 | -91% | 1 | 1 | 0% | 2,374 | 1,782 | -25% | 0 | 0 | — |
case-11 | fail→pass | 13,620 | 2,886 | -79% | 1 | 1 | 0% | 2,535 | 1,804 | -29% | 0 | 0 | — |
case-01 | fail→pass | 11,328 | 7,564 | -33% | 1 | 1 | 0% | 2,063 | 2,765 | +34% | 0 | 0 | — |
case-02 | fail→pass | 22,405 | 2,996 | -87% | 1 | 1 | 0% | 3,900 | 1,832 | -53% | 0 | 0 | — |
case-03 | fail→pass | 10,761 | 7,873 | -27% | 1 | 1 | 0% | 1,998 | 2,765 | +38% | 0 | 0 | — |
case-04 | fail→fail | 11,642 | 6,523 | -44% | 1 | 1 | 0% | 2,266 | 2,538 | +12% | 0 | 0 | — |
case-05 | fail→fail | 13,091 | 4,956 | -62% | 1 | 1 | 0% | 964 | 2,218 | +130% | 0 | 0 | — |
case-06 | fail→pass | 14,022 | 5,113 | -64% | 1 | 1 | 0% | 2,602 | 2,254 | -13% | 0 | 0 | — |
case-07 | fail→pass | 19,164 | 2,616 | -86% | 1 | 1 | 0% | 3,547 | 1,747 | -51% | 0 | 0 | — |
case-08 | fail→pass | 23,684 | 3,706 | -84% | 1 | 1 | 0% | 4,636 | 2,028 | -56% | 0 | 0 | — |
case-12 | fail→pass | 14,878 | 3,297 | -78% | 1 | 1 | 0% | 2,830 | 1,920 | -32% | 0 | 0 | — |
case-13 | fail→pass | 16,985 | 3,247 | -81% | 1 | 1 | 0% | 1,811 | 1,877 | +4% | 0 | 0 | — |
case-14 | fail→pass | 6,648 | 3,760 | -43% | 1 | 1 | 0% | 1,147 | 1,951 | +70% | 0 | 0 | — |
case-15 | fail→pass | 14,704 | 8,628 | -41% | 1 | 1 | 0% | 2,634 | 2,882 | +9% | 0 | 0 | — |
case-16 | fail→pass | 11,169 | 7,017 | -37% | 1 | 1 | 0% | 2,065 | 2,665 | +29% | 0 | 0 | — |
case-17 | fail→pass | 17,912 | 2,968 | -83% | 1 | 1 | 0% | 2,948 | 1,828 | -38% | 0 | 0 | — |
case-18 | fail→pass | 17,754 | 15,188 | -14% | 1 | 1 | 0% | 3,480 | 4,528 | +30% | 0 | 0 | — |
case-19 | fail→pass | 7,865 | 4,788 | -39% | 1 | 1 | 0% | 1,450 | 2,188 | +51% | 0 | 0 | — |
case-20 | pass→pass | 4,717 | 6,407 | +36% | 1 | 1 | 0% | 801 | 2,438 | +204% | 0 | 0 | — |
case-21 | pass→fail | 34,462 | 4,844 | -86% | 1 | 1 | 0% | 7,402 | 2,171 | -71% | 0 | 0 | — |
case-22 | pass→fail | 12,416 | 5,739 | -54% | 1 | 1 | 0% | 2,558 | 2,321 | -9% | 0 | 0 | — |
case-23 | fail→fail | 9,398 | 6,297 | -33% | 1 | 1 | 0% | 1,698 | 2,464 | +45% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +65 percentage points is the difference between those two pass rates over the 23 comparable cases. 2 cases got worse with the skill loaded, and they are included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
| Model | Method | Date | Lift |
|---|---|---|---|
| gemini-3.6-flash | verified | 8/21/2026 | +50% |
Other measured skills in the registry, with their headline benchmark lift.