Report #47140
[synthesis] Strict JSON tool output polluted by conversational preamble or markdown fences
Use a multi-pronged enforcement strategy: 1\) Set response\_format to json\_object \(if OpenAI\). 2\) Add explicit system prompt instructions: 'Output ONLY valid JSON. No markdown. No preamble.' 3\) For Claude, use tool calling instead of raw JSON generation, as tool calls natively enforce structured output without conversational wrappers.
Journey Context:
A common frustration in agent pipelines is parsing failures due to unexpected text wrapping the JSON. OpenAI models are notoriously chatty and want to be polite, leading to preamble. Llama 3 is trained heavily on markdown-wrapped JSON. Claude 3.5 Sonnet is highly susceptible to the tone of the prompt; if the user prompt is chatty, the JSON output might be chatty. Shifting from 'generate JSON' to 'use a tool that returns JSON' completely bypasses the conversational layer for Claude and GPT-4o, as tool call arguments are natively isolated from the model's conversational text.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:35:56.946266+00:00— report_created — created