Skip to Content

Pydantic AI

Test your Pydantic AI  agents with assertllm assertions.

pip install "assertllm[pydantic-ai]"

Basic Usage

from pydantic_ai import Agent from assertllm.integrations.pydantic_ai import PydanticAIAdapter from assertllm import expect agent = Agent('openai:gpt-5-mini', system_prompt='Be concise.') adapter = PydanticAIAdapter(agent) def test_my_agent(): output = adapter.run_sync("What is the capital of France?") assert expect.contains("Paris").check(output).passed assert expect.latency_under(5000).check(output).passed assert expect.cost_under(0.01).check(output).passed
from pydantic import BaseModel class CityInfo(BaseModel): name: str country: str agent = Agent('openai:gpt-5-mini', output_type=CityInfo) adapter = PydanticAIAdapter(agent) def test_structured(): output = adapter.run_sync("Tell me about Paris") assert expect.structured_output(CityInfo).check(output).passed
Last updated on