How should an agent recover when the previous turn produced output that failed schema validation?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Show the model its failed output verbatim, the validator's structured error pointing at the exact failing field and constraint, the original task and evidence, and request only the corrected JSON, then cap retries
Imagine asking a friend to fill out a form and they get one field wrong. The wrong way to fix it is to hand them a blank form and say try again, they will probably make the same mistake. The right way is to hand them their filled-out form back, point at the wrong field, and say what the rule was. Now they can see exactly what to change. If they still cannot get it after one or two tries, do not keep asking forever, fall back to filling it in yourself or skipping the field.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Describe the four context pieces in the repair turn: original task plus evidence, failed output verbatim, structured validator error with field path and constraint, and a precise instruction to produce only the corrected JSON. Explain why a structured error beats a generic try again, why diff-style repair beats regeneration, and why retries should be capped at one or two. Cover fallback strategies (safe defaults, partial extraction, human review, model escalation). Mention structured-output modes from providers as the first-line prevention. Close with the operational discipline of instrumenting the repair loop to monitor pipeline health.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Resending the same prompt with a generic try again message and watching the model produce the same broken JSON until the retry loop burns the budget.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.