Skip to main content
Parser examples enact what happens when the LLM gets the JSON contract slightly wrong. Sources under examples/parsers/.

How to run

When to use which

  • OutputFixingParser — model is capable of valid JSON but slipped this time. Cheaper: one repair attempt with the parse error in the prompt.
  • RetryParser — one repair pass isn’t enough; loop fixer + parse up to N times. More expensive but more robust against models that produce different-but-still-broken JSON each attempt.
In production, layer them: RetryParser::with_retries(OutputFixingParser::new(inner, fixer), 3).

See also

Structured output

The user guide for parsers and recovery strategies.

Examples → Chains

chains_structured_parsing shows the parsers in a chain.