Skip to content

Failures with no errors · 5 of 8

The parse-retry loop

Step 1 · The pattern

Ask for JSON, parse the text

The prompt says 'reply in JSON with these fields' and the app parses the text. On short, ordinary documents it parses almost every time; the occasional failure is retried once and works. (All numbers are illustrative.)

  • a request
  • retry
  • parsed

In short

The parse-retry loop: how it works and how it breaks

Many LLM features need machine-readable output: JSON for an API, a tool call, fields for a form. The first version usually asks for JSON in the prompt and parses the text. It works most of the time. When it does not, a missing brace or an extra sentence, the app asks again, and each retry is another full model call. Cost and latency grow on exactly the hardest inputs, some requests fail after every retry, and nothing alerts, because each call succeeded. Structured outputs constrain generation to a JSON schema; Anthropic's documentation describes guaranteed schema-compliant responses with no retries needed for schema violations. Keep validation in code for rules a schema cannot express, check the stop reason, and graph parse failures and retries wherever free text is still parsed.

What this simulation simplifies

  • Parse failure rates are fixed chances here; real rates depend on the model, prompt and input.
  • Retries go back to the same model with the same input.

How this comes up in interviews

"You need an LLM to fill in a form from documents, reliably. How do you design the output handling?"

Then they ask

  1. What happens when the output does not parse?
  2. What can a schema not check?
  3. How do you monitor it?

A strong answer covers

  • Free-text JSON fails on hard inputs; retries multiply cost and latency.
  • Use structured outputs (schema-constrained decoding) where available.
  • Validate business rules in code; check stop reasons.
  • Cap retries; graph parse-failure and retry rates.
  • Keep schemas within the provider's supported features.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last reviewed: Official documentation

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.