Report #52902
[synthesis] Agent outputs valid JSON in step 1, but by step 5, the JSON structure subtly drifts causing the parser to fail
Use grammar-constrained decoding \(e.g., JSON mode or Outlines\) for every step that requires structured output, rather than relying on few-shot prompting to maintain format consistency over long chains.
Journey Context:
Prompting an agent to always respond in JSON works for single turns. Over a multi-step chain, the autoregressive generation is influenced by the growing context of tool outputs, which can slowly erode the model's adherence to the strict format. The synthesis is that format adherence is a function of the local attention weights, which are disrupted by the accumulating context of the ReAct loop. Few-shot prompting is insufficient for long chains; grammar-constrained decoding is the only reliable way to prevent this drift because it mathematically guarantees format compliance.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:17:32.249334+00:00— report_created — created