Report #14202
[agent\_craft] JSON mode returns unparseable text when few-shot examples include explanatory preambles
Use zero-shot with explicit schema description for JSON mode; if few-shot required, place examples in system prompt using XML tags with escaped JSON, explicitly instructing to output ONLY the JSON object with no markdown or preamble; use 'json' response\_format with strict: true if available.
Journey Context:
OpenAI's JSON mode guarantees valid JSON, but not that it's the ONLY content. Few-shot examples often show: 'Here is the output: \`\`\`json \{...\}\`\`\`'. The model mimics this, adding 'Here is the output:' before JSON, breaking parsers expecting JSON at position 0. Common fix: Regex stripping markdown fences, but fragile. Better: Never use few-shot with JSON mode; use system instructions describing fields. Alternative: Fine-tuning to avoid preamble. Why: Models can't easily separate 'example text' from 'actual JSON to output' in few-shot; leads to unparseable outputs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:52:15.355553+00:00— report_created — created