Report #30943
[frontier] LLM returning malformed JSON causing downstream pydantic validation errors
Replace regex post-processing with finite-state machine constrained generation using Outlines or Guidance; pre-compile the JSON schema into a FSM that constrains token sampling at the logits level, guaranteeing 100% valid output.
Journey Context:
The standard approach is to prompt for JSON and then parse with \`json.loads\`, catching exceptions and retrying. This fails unpredictably with nested schemas or unicode escapes. The 2024-2025 breakthrough is applying constrained decoding: libraries like Outlines compile JSON schemas into regular expressions, then into FSMs that mask invalid tokens during sampling. This eliminates retries and latency variance. The tradeoff is setup time for the FSM, but for agent tool calling where schema adherence is critical, this is now the production standard over prompt engineering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:19:32.486214+00:00— report_created — created