cost. Each retry is another LLM call.
Who it is forA developer whose pipeline breaks on the occasional malformed answer.
The problemInvalid LLM output means manual retries and error handling code.
The outcomeData that passes your validators, with retries handled for you.
What you need first
- Python with pip, uv or poetry
- An API key for your provider, or a local Ollama install
- Basic Pydantic knowledge
Steps
- Install with
pip install instructor - Add a field_validator to your Pydantic model, for example on age
- Call client.chat.completions.create with response_model as usual
- Failed validations are retried with the error message, per the Automatic retries section
Prompt for your agent
Using 567-labs/instructor, add Pydantic field_validator rules for <my business rules> to my model and show how Instructor's automatic retries handle an input that fails them the first time.
Caveat. For agents with observability and traces, the README itself points to PydanticAI.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for 567-labs/instructor and "Retry automatically when the LLM output fails validation"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer