Pydantic AI observability — drop-in. ~5 minutes.
Pydantic AI's typed function calls and structured outputs map cleanly to OpenTelemetry GenAI spans. Validation failures surface as first-class events so you can see exactly which output broke the schema.
What we capture for Pydantic AI
- Agent.run / run_sync / run_stream invocations as root spans
- Tool calls with typed args and validated outputs
- ValidationError events with the exact field path and value
- Streamed token deltas attributed to the agent step
- Per-run usage: input tokens, output tokens, total cost
- Multi-model fallbacks and their selection reasons
Install
# Python pip install trefur-observe pydantic-ai export TREFUR_API_KEY=trf_obs_REPLACE_ME
Instrument
from trefur_observe import TrefurObserve, patch_pydantic_ai
from pydantic import BaseModel
from pydantic_ai import Agent
obs = TrefurObserve.init(api_key="trf_obs_...")
patch_pydantic_ai(obs)
class SupportSummary(BaseModel):
customer: str
priority: str # 'low' | 'normal' | 'high' | 'urgent'
next_action: str
agent = Agent(
"openai:gpt-4o",
output_type=SupportSummary,
system_prompt="Summarise the support ticket into the schema.",
)
result = agent.run_sync(
"Customer A-42 reports a charge they don't recognise."
)
print(result.output)
# Trace appears in https://app.trefur.com — typed output captured.What a Pydantic AI trace looks like
Three common Pydantic AI pain points, and what Trefur shows you
ValidationError on output
The model returns a field name the schema doesn't accept and Pydantic AI raises ValidationError. Trefur surfaces the raw model output alongside the validation trace so you can pin the prompt fix.
Tool-arg coercion failures
A typed tool arg fails to coerce and the agent retries with a slightly different prompt. Trefur shows the coercion failure and the retry attempts so you can see whether to widen the schema or tighten the prompt.
Model fallback you didn't notice
Multi-model agents fall back to a slower model when the primary fails. Trefur captures the selection reason on the span so you can correlate cost spikes with fallback events.
FAQ
Does it work with async agents?+
Yes. agent.run, agent.run_sync, agent.run_stream — all three paths emit equivalent spans.
Streaming with run_stream?+
Yes. The streamed deltas are coalesced into a single span with the final output; intermediate deltas are recorded as events.
Multiple LLM providers?+
OpenAI, Anthropic, Bedrock, Gemini, Groq — every provider Pydantic AI supports is captured with the right gen_ai.system attribute.
Custom output validators?+
Validators decorated with @output_validator emit a span with the validation result. Failures show the field path and the offending value.
Ship Pydantic AI agents you can debug.
Free tier. No card required. First trace in under five minutes.