Pydantic AI & Instructor Best Practices
Ten practices for schema design that keeps validated agent output both strict and useful.
Use this list when reviewing Pydantic models, agent output_type choices, Instructor extractors, and typed tools.
Search across all documentation pages
Ten practices for schema design that keeps validated agent output both strict and useful.
Use this list when reviewing Pydantic models, agent output_type choices, Instructor extractors, and typed tools.
output_type. Tools intermediate; final output terminates with an explicit success or typed failure.max_retries / output retry budgets stay small; error text teaches the repair.NeedMoreInfo, Rejected, or Escalate beat infinite reask on impossible inputs.Items 1-10 are the core schema and wiring practices. Items 11-15 extend them into operations so the list stays useful after launch.
Required fields for anything you will act on, plus enums for closed sets. Most silent failures come from optional mush.
If mean retries stay high on good inputs, loosen optionality, split models, or improve descriptions before raising retry caps.
No. Structure the surfaces that software consumes: tools, handoffs, forms, and commits. Pure human-readable answers can stay text.
1-5 and 7, 11-13 apply directly. 6, 8-10, 14-15 matter as soon as you grow into tools or agents.
In PR review next to agent code, with a short golden-set run for first-try pass rate when fields change.
Keep schemas provider-agnostic. Pin model-specific output modes (native vs tool vs prompted) in config, not in the domain model.
Policy and role go in instructions. Shape, types, and closed values go in schema. Duplicating closed sets only in prose causes drift.
Require a named consumer for every new field. No consumer, no field. Nested "misc" dicts are rejected in review.
As soon as retries would otherwise loop on missing user data or policy blocks. Host apps need a clean branch, not an exception soup.
No. They reduce parse failures. Evals still catch wrong-but-valid content and bad tool choices.
Least-privilege tools, validation before side effects, and no secrets in error/retry text are security controls as much as quality controls.
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.
Reviewed by Chris St. John·Last updated Jul 16, 2026