pydantic-ai-testing

Test PydanticAI agents deterministically with TestModel, FunctionModel, and VCR cassettes.

75|9|Updated Dec 21, 2025
One-click install
npx skills add https://github.com/anderskev/beagle --skill pydantic-ai-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pydantic-ai-testing
Source: https://github.com/anderskev/beagle/tree/main/skills/pydantic-ai-testing
Command: npx skills add https://github.com/anderskev/beagle --skill pydantic-ai-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It describes deterministic testing patterns for PydanticAI-based agents, including TestModel, FunctionModel, VCR cassettes, and inline snapshots.

Core Features & Use Cases

  • Deterministic Runs: Use TestModel for reproducible outputs.
  • Tool Calls & Dependencies: Force tool calls and mock dependencies.
  • Cassettes & Snapshots: Record interactions for replay and assertions.

Quick Start

Create a TestModel, run a run_sync with an agent, and assert deterministic outputs.

Frequently Asked Questions about pydantic-ai-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test PydanticAI agents without making live API calls?

Use TestModel to run deterministic tests of PydanticAI agents without calling external APIs. TestModel replaces live LLM responses with controlled outputs, enabling reproducible unit tests and eliminating API dependencies during development.

Can I mock LLM responses and force specific tool calls in PydanticAI tests?

Yes. FunctionModel and TestModel allow you to mock LLM responses and force specific tool calls, giving you complete control over agent behavior during testing. This lets you validate tool invocation logic independently of LLM output.

How do I record and replay API interactions for PydanticAI agent tests?

Use VCR cassettes to record API interactions during test runs and replay them on subsequent runs. This approach captures real responses once, then replays them deterministically without repeated API calls, integrating with pytest test infrastructure.

What's the best way to assert deterministic outputs from PydanticAI agents?

Combine TestModel with inline snapshots and seed control to generate and assert deterministic agent outputs. Inline snapshots capture expected outputs inline in test code, and controlled seeds ensure reproducible results across test runs.

Can I override dependencies when testing PydanticAI agents?

Yes. PydanticAI testing patterns support dependency overrides, letting you inject mock implementations of external services and databases during tests. This isolates agent logic from infrastructure and ensures tests remain fast and deterministic.