Repair Invalid JSON with a Targeted Re-Ask
Explore how to construct focused correction prompts that repair invalid JSON outputs in AI workflows. Learn to enforce minimal changes, preserve valid data, and handle missing information safely by routing cases needing human review. This lesson helps you implement robust validation and repair steps to maintain reliable automation.
We'll cover the following...
When a model returns structurally valid JSON with a type mismatch, for example, "needs_human": "false" instead of the boolean value false, a strict validator will reject the output. Re-running the full triage prompt on the original email consumes additional tokens and may introduce new classification errors. A better option is often a targeted repair step: a focused correction prompt that treats the invalid JSON as input and fixes only the schema violations without changing the underlying classification. In this lesson, we will explore how to construct minimal-change correction prompts that repair schema-invalid output while enforcing explicit stop conditions when required data is missing.
The table below shows four common ways model output breaks, with an example of each and how a strict parser or schema validator responds. The first two fail at parsing, and the last two parse but fail schema validation:
The pattern to keep in mind is simple. When validation fails, a targeted re-ask treats the invalid output as data, requests a corrected version, and forbids extra prose so the next system step can parse it.
Build a correction re-ask prompt
With the symptom identified, the next move is to write ...