Report #87286
[synthesis] LLM wraps strict JSON tool outputs in markdown backticks or adds conversational filler
Use native structured output features \(e.g., GPT-4o strict schema\) rather than relying on prompt-based JSON formatting, and implement a regex-based fence-stripping sanitizer in the agent loop as a universal fallback.
Journey Context:
Developers often prompt 'Respond ONLY with valid JSON'. GPT-4o might still add conversational text before the JSON unless forced by API flags. Claude 3.5 Sonnet frequently prepends tags or wraps output in \`\`\`json. Gemini 1.5 Pro is the worst offender for adding \`\`\`json fences even when told not to. Prompting alone is insufficient. The synthesis is that you must use provider-specific API levers for strict JSON where available, but because no model perfectly obeys prompt-only constraints 100% of the time, a post-processing sanitizer is mandatory for cross-model resilience.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:05:53.256578+00:00— report_created — created