JSON
Why Forcing JSON Output Hurts LLM Reasoning — And How to Fix It (Breakdown)
1. The Paper & Open-Source Code
- Paper: Zhi Rui Tam*, Cheng-Kuang Wu*, Yi-Lin Tsai, Chieh-Yen Lin, Hung-yi Lee, and Yun-Nung Chen (Appier AI Research & National Taiwan University), "Let Me Speak Freely? A Study on the Impact of Format Restrictions on Performance of Large Language Models" — EMNLP 2024 Industry Track (
arXiv:2408.02442v3).- Read it here: https://arxiv.org/abs/2408.02442
- Official Code & Two-Stage Parser (
2stage_parsing.py):
2. What They Tested
- Models:
GPT-3.5-Turbo,Claude-3-Haiku,Gemini-1.5-Flash,LLaMA-3-8B-Instruct,Gemma-2-9B-Instruct, plusGPT-4o-mini(with OpenAI Context-Free GrammarJSON-Schema). - Tasks: 3 multi-step reasoning benchmarks (
GSM8K,Last Letter Concatenation,Shuffled Objects) and 4 classification benchmarks (DDXPlus,MultiFin,Sports Understanding,NI Task 280).
3. The Key Findings
- Strict JSON schemas degrade multi-step reasoning — not just syntax:
- On
GSM8Kmath, adding a strict JSON schema droppedGPT-3.5-Turbofrom 76.0% to 49.3% (-26.7pts) even though JSON parsing errors were only 0.13%. - On
Last Lettersymbolic logic,LLaMA-3-8Bsuffered a 38.2-point drop in JSON despite only 0.15% parsing errors.
- On
- The key-order trap:
- In
JSON-mode, 100% ofGPT-3.5-Turboresponses emitted"answer"BEFORE"reason"— forcing the model to guess the answer before thinking step by step.
- In
- The honest catch:
- On pure classification tasks (
DDXPlus,Sports,MultiFin),JSON-modematched or outperformed plain text by constraining the label space. - Newer grammar-enforced
JSON-SchemaAPIs (gpt-4o-mini) shrank the gap (94.6%NL vs91.7%JSON-Schema vs87.0%JSON-mode onGSM8K), though free text still won on 2 of 3 reasoning tasks.
- On pure classification tasks (
4. The Practical Fix for Your LLM Stack
- Use two-step
NL-to-Formatfor hard reasoning: Let your main model think and answer in unrestricted plain text first, then run a fast, cheap second call (2stage_parsing.py) to extract the structured JSON. In the paper, this recovered nearly all natural-language accuracy while preserving valid JSON. - If you must use single-call Structured Outputs, force
"reasoning"FIRST: Never let the schema or JSON mode emit"answer"before"reasoning", and keep schemas as flat and minimal as possible. - Reserve strict
JSON-modefor classification & extraction: Where the model is picking labels rather than doing multi-step reasoning, strict JSON schemas help instead of hurt.
FREE ONE-TIME UNLOCK
Unlock the full JSON breakdown
Drop your email once to read the complete step-by-step guide, grab the files, and unlock all 96 Reel breakdowns on this device forever.
✓ Instant reveal right here✓ No spam, unsubscribe any time