Repair Invalid JSON with a Targeted Re-Ask
Explore techniques to repair invalid JSON output in AI workflows by constructing focused re-ask prompts that fix schema violations without altering underlying meanings. Learn to enforce minimal changes and handle missing data safely to improve automation reliability.
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 a re-ask that ...