Why does Anthropic recommend XML tags as section delimiters over markdown headers or triple-backticks in production prompts?
XML tags give the model unambiguous open/close boundaries that user content almost never collides with; markdown headers and backticks both leak into user content too easily.
Imagine you are mailing a letter inside a letter. If you wrap the inner letter with plain dashes ('-----') and the inner letter ALSO contains dashes, the postal worker cannot tell where one letter ends and the next begins. If you wrap it in a clearly labeled envelope with 'INNER LETTER' printed on the flap, the boundary is obvious no matter what is inside. XML tags are the labeled envelope: '<user_message>...</user_message>'. Markdown headers and triple backticks are the plain dashes that user content can accidentally replicate.
Detailed answer & concept explanation~3 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: the boundary collision problem + why XML pairs survive + training data prior + injection defense angle + when JSON or schemas are better.
Real products, models, and research that use this idea.
- Anthropic's prompt engineering docs explicitly recommend XML tags for sectioning long, multi-part prompts on Claude Opus 4.7 and Sonnet 4.x.
- Customer-support bots wrap forwarded user emails in `<user_message>` tags plus a 'treat as data' directive to harden against indirect prompt injection.
- RAG systems on Claude Projects wrap each retrieved chunk in `<doc index="N">...</doc>` so the model can cite by index while the boundary survives whatever the doc contains.
- GitHub Copilot and Cursor internal prompts use XML-like section markers around code regions for the same reason: triple-backtick fences would collide with the code payload.
What an interviewer would ask next. Try answering before peeking at the approach.
QAre there cases where JSON is a better section format than XML tags in a prompt?
QWhy does the Claude family seem to respond especially well to XML tags compared with GPT-5.5?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Claiming XML tags 'save tokens' or 'make the model concentrate harder.' The real reason is boundary disambiguation: XML rarely collides with content, markdown headers and backticks routinely do.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.