Skip to content
Skillv1.0.0

pydantic-ai

You are an expert in PydanticAI, the Python agent framework built by the Pydantic team. You help developers create type-safe AI agents with structured outputs, dependency injection, tool definitions,

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/pydantic-ai/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill pydantic-ai. Copyright stays with the author (Apache-2.0).

PydanticAI — Agent Framework by Pydantic Team

You are an expert in PydanticAI, the Python agent framework built by the Pydantic team. You help developers create type-safe AI agents with structured outputs, dependency injection, tool definitions, streaming, and model-agnostic design — leveraging Pydantic for validation and type safety throughout the agent lifecycle.

Core Capabilities

from pydantic_ai import Agent
from pydantic import BaseModel

class CityInfo(BaseModel):
    name: str
    country: str
    population: int
    famous_for: list[str]

agent = Agent("openai:gpt-4o", result_type=CityInfo,
    system_prompt="You provide accurate city information.")

result = agent.run_sync("Tell me about Tokyo")
print(result.data)  # CityInfo(name='Tokyo', country='Japan', population=13960000, ...)

# With tools and dependencies
from dataclasses import dataclass

@dataclass
class Deps:
    db: Database
    user_id: str

support_agent = Agent("openai:gpt-4o", deps_type=Deps,
    system_prompt="You are a customer support agent.")

@support_agent.tool
async def get_order(ctx, order_id: str) -> dict:
    """Look up an order by ID."""
    return await ctx.deps.db.orders.find(order_id)

@support_agent.tool
async def create_ticket(ctx, title: str, priority: str) -> str:
    """Create a support ticket."""
    ticket = await ctx.deps.db.tickets.create(title=title, priority=priority, user_id=ctx.deps.user_id)
    return f"Created ticket {ticket.id}"

result = await support_agent.run("Where is my order ORD-123?", deps=Deps(db=db, user_id="u42"))

# Streaming
async with support_agent.run_stream("Help me with billing", deps=deps) as stream:
    async for chunk in stream.stream():
        print(chunk, end="", flush=True)

Installation

pip install pydantic-ai

Best Practices

  1. result_type — Use Pydantic models for structured output; validated automatically
  2. Dependency injection — Pass deps (DB, auth, config) via deps_type; clean, testable architecture
  3. @agent.tool — Decorate functions as tools; type hints become the schema; docstring becomes description
  4. Model-agnostic — Works with OpenAI, Anthropic, Gemini, Groq, Mistral, Ollama
  5. Streamingrun_stream() for real-time token delivery; structured result available at end
  6. Testing — Use TestModel for deterministic testing without API calls
  7. Logfire integration — Built-in observability via Pydantic Logfire; trace every agent step
  8. System prompts — Dynamic system prompts via @agent.system_prompt decorator; context-aware

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-pydantic-ai/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-pydantic-ai.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-pydantic-ai",
  "kind": "skill",
  "name": "pydantic-ai",
  "description": "You are an expert in PydanticAI, the Python agent framework built by the Pydantic team. You help developers create type-safe AI agents with structured outputs, dependency injection, tool definitions, streaming, and model-agnostic design — leveraging Pydantic for validation and type safety throughout the agent lifecycle.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "agent",
      "pydantic",
      "python",
      "type-safe",
      "tools",
      "structured-output",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "You are an expert in PydanticAI, the Python agent framework built by the Pydantic team. You help developers create type-safe AI agents with structured outputs, dependency injection, tool definitions, streaming, and model-agnostic design — leveraging Pydantic for validation and type safety throughout the agent lifecycle."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/pydantic-ai/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/pydantic-ai/SKILL.md",
      "key": "terminalskills/skills/skills/pydantic-ai/SKILL.md"
    },
    "license": "Apache-2.0"
  },
  "instructions": "# PydanticAI — Agent Framework by Pydantic Team\n\nYou are an expert in PydanticAI, the Python agent framework built by the Pydantic team. You help developers create type-safe AI agents with structured outputs, dependency injection, tool definitions, streaming, and model-agnostic design — leveraging Pydantic for validation and type safety throughout the agent lifecycle.\n\n## Core Capabilities\n\n```python\nfrom pydantic_ai import Agent\nfrom pydantic import BaseModel\n\nclass CityInfo(BaseModel):\n    name: str\n    country: str\n    population: int\n    famous_for: list[str]\n\nagent = Agent(\"openai:gpt-4o\"",
  "cost": {
    "context_tokens": 645
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-pydantic-ai/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.