existential-birds avatar

Pydantic Ai Common Pitfalls

Catches the decorator and type annotation mistakes that trip up PydanticAI users most often. Shows you which tools need RunContext and which don't, how to fix "First parameter must be annotated with RunContext" errors, and why your deps aren't wiring up correctly. The debugging section is genuinely helpful: it walks you through message capture, explains when raw function registration is actually valid (despite looking wrong), and includes a gate checklist for those frustrating cases where the agent just silently does the wrong thing. Worth keeping open when you're setting up new agents or reviewing tool definitions, especially if you're switching between sync and async patterns.

skills.sh installs
221
GitHub stars
87
last updated
Aug 21, 2026

Install

$ npx -y skills add existential-birds/beagle --skill pydantic-ai-common-pitfalls --agent claude-code

Installs into .claude/skills of the current project.

Files

PydanticAI Common Pitfalls and Debugging

Tool Decorator Errors

Wrong: RunContext in tool_plain

# ERROR: RunContext not allowed in tool_plain
@agent.tool_plain
async def bad_tool(ctx: RunContext[MyDeps]) -> str:
    return "oops"
# UserError: RunContext annotations can only be used with tools that take context

Fix: Use @agent.tool if you need context:

@agent.tool
async def good_tool(ctx: RunContext[MyDeps]) -> str:
    return "works"

Wrong: Missing RunContext in tool

# ERROR: First param must be RunContext
@agent.tool
def bad_tool(user_id: int) -> str:
    return "oops"
# UserError: First parameter of tools that take context must be annotated with RunContext[...]

Fix: Add RunContext as first parameter:

@agent.tool
def good_tool(ctx: RunContext[MyDeps], user_id: int) -> str:
    return "works"

Wrong: RunContext not first

# ERROR: RunContext must be first parameter
@agent.tool
def bad_tool(user_id: int, ctx: RunContext[MyDeps]) -> str:
    return "oops"

Fix: RunContext must always be the first parameter.

Valid Patterns (Not Errors)

Raw Function Tool Registration

Sponsors

Details

Repository
github.com/existential-birds/beagle
Categories
AI & Agent Building, Debugging, Python
First seen
Jun 3, 2026

More from existential-birds/beagle

All 40
1bobmatnyc avatarmcpbobmatnyc/claude-mpm-skillsMCP (Model Context Protocol) - Build AI-native servers with tools, resources, and prompts. TypeScript/Python SDKs for Claude Desktop integration.206skills.sh installs
2slowmist avatarslowmist-agent-securityslowmist/slowmist-agent-securityComprehensive security review framework for AI agents. Covers skill/MCP installation, GitHub repos, URLs/documents, on-chain addresses, products/services, and s205skills.sh installs
3lobehub avataragent-tracinglobehub/lobehubAgent tracing CLI for execution snapshots. Use for agent-tracing, traces, snapshots, LLM call inspection, context engine data, agent step analysis, execution de195skills.sh installs
4dkyazzentwatwa avatarmcp-builderdkyazzentwatwa/chatgpt-skillsPlan and build MCP servers with agent-friendly tools, schemas, error handling, and evaluation. Use when creating or refactoring MCP integrations.194skills.sh installs
5melodic-software avatarsystem-prompt-engineeringmelodic-software/claude-code-pluginsDesign effective system prompts for custom agents. Use when creating agent system prompts, defining agent identity and rules, or designing high-impact prompts t170skills.sh installs
6dicklesworthstone avataragent-swarm-workflowdicklesworthstone/agent_flywheel_clawdbot_skills_and_integrationsJeffrey Emanuel's multi-agent implementation workflow using NTM, Agent Mail, Beads, and BV. The execution phase that follows planning and bead creation. Include169skills.sh installs