New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
The model's JSON is almost right every time, one field off, and I keep fixing it by hand instead of just asking again.
What you'll have at the end
A retry function that appends the validation error to the next prompt and logs how many tries each request needed
You need
You already have a request that attaches a JSON Schema to a provider's schema-enforced call, plus a typed model such as Pydantic or Zod whose own checks raise a real error when a reply's fields don't hold together.
Not covered
The semantic checks that need a second LLM call to judge tone or factual correctness, not a rule your own typed model can check directly on a reply it already rejected.
Leans on
Your Pydantic model fails OpenAI's strict mode
when every retry fails the exact same way because the schema itself is malformed rather than the model's answer
A hallucinated phone number breaks the record
when the reply clears every check cleanly but a value inside it is still a plausible-looking lie; no retry catches a value nothing flags as wrong
Checked 15 Aug 2026
Part of the Structured Output Generation with LLMs cookbook