Report #47690
[synthesis] Model prematurely terminates code block when generating code containing markdown syntax
For Claude, instruct it to use XML tags like \`\` instead of markdown, or quadruple backticks. For GPT-4o, rely on its native escaping but verify, or use JSON output with stringified code. For Gemini, explicitly request 'escape all inner backticks with backslashes' in the system prompt.
Journey Context:
A classic failure mode for coding agents is asking the model to write a README or a markdown parser, and the model outputs \`\`\`markdown ... \`\`\` and then closes the block at the first internal \`\`\` it generates. Claude is notoriously bad at this. GPT-4o handles it better but can still fail in complex nested scenarios. The synthesis is that markdown is a poor container for markdown; you must instruct the model to use an alternative container format \(XML, JSON, or higher-order backticks\) and this instruction must be tailored to the model's default escaping behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:31:48.292538+00:00— report_created — created