Report #44538
[counterintuitive] Do few-shot examples guarantee LLM JSON output
Use constrained decoding \(logit masking/grammars\) or native structured output features \(like JSON mode/function calling\) instead of relying solely on few-shot examples for formatting.
Journey Context:
Providing a few examples of JSON outputs leads developers to believe the model will always output valid JSON. LLMs are probabilistic; complex schemas, edge cases in user input, or trailing commas can easily break the pattern. Constrained decoding forces the model to only emit tokens that conform to the provided grammar/schema, guaranteeing 100% structural validity and eliminating the need for regex-based post-processing fixes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T05:13:33.411179+00:00— report_created — created