DEDUPED Hot AI repos. Real use cases. What people build. Get the Monday 5

How to retry automatically when the LLM output fails validation with Instructor

Add Pydantic field validators and let Instructor resend the error to the model until the data is valid.

Short answer: Install with pip install instructor; then add a field_validator to your Pydantic model, for example on age; call client.chat.completions.create with response_model as usual. All steps.

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

  1. Install with pip install instructor
  2. Add a field_validator to your Pydantic model, for example on age
  3. Call client.chat.completions.create with response_model as usual
  4. 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

Cursor, ChatGPT, others

Share: X LinkedIn Hacker News Email Copy link

Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer