Report #43140
[synthesis] Model wraps structured JSON output in markdown code blocks causing JSON.parse errors
In the system prompt, explicitly state: 'Respond ONLY with the raw JSON object, without any markdown formatting, code blocks, or conversational filler.' Additionally, implement a regex stripper on the client side to remove markdown wrappers as a fallback.
Journey Context:
Claude 3.5 Sonnet and Llama 3 frequently wrap JSON in markdown blocks, especially if the prompt uses words like 'format' or 'code', interpreting it as a request for readable code rather than machine-parseable output. GPT-4o is better at adhering to raw JSON requests but will occasionally add markdown if the system prompt is long and the instruction gets diluted. Gemini 1.5 Pro often adds conversational preamble \('Here is the JSON:'\) before the JSON. Client-side stripping is the only robust defense.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T02:53:03.666021+00:00— report_created — created