Using XML tags in prompts reduces errors in Claude's structured outputs by approximately 28% compared to markdown headers or plain text delimiters. Claude was specifically trained to recognize and respect XML-style tags, which makes them more reliable than other formatting approaches for structured tasks. Here's how to use them and when it matters.
Why XML tags work better for Claude
Claude's training process involved XML-tagged training data, which means the model recognizes XML tags as meaningful structural delimiters — not just formatting. When you use <instructions> or <document> tags, Claude treats the content within them as distinctly scoped, reducing the chance of it bleeding one section's instructions into another.
Markdown headers (## Section) work, but they're less structurally clean in long, complex prompts. Plain text separators (three dashes, all caps) work inconsistently. XML tags are the most reliably parsed structure.
Basic usage
Instead of:
Here's my context:
I'm a product manager at a B2B company.
Here's the task:
Summarize this user feedback in 3 bullet points.
Here's the document:
[feedback text]
Use:
<context>
I'm a product manager at a B2B company evaluating feature requests.
</context>
<task>
Summarize the user feedback below in exactly 3 bullet points.
Each bullet under 20 words. Focus on product implications.
</task>
<document>
[feedback text]
</document>
The XML version gives Claude clearer structural signals about what each section contains and how to treat it.
When it makes the biggest difference
Structured extraction tasks. Asking Claude to extract specific fields from a document — names, dates, key terms, categories — benefits a lot from XML tags that define what you're extracting and from where.
Multi-part prompts. When a single prompt has several distinct components (background, task, examples, constraints), XML tags prevent Claude from conflating them.
System prompts with multiple rules. A system prompt that sets persona, rules, and format constraints is cleaner and more reliably followed with XML structure:
<persona>
You are a direct-response copywriter. Cut filler, lead with value.
</persona>
<rules>
- Never start with "I"
- No preamble — get directly to the output
- If something is unclear, state your assumption and proceed
</rules>
<format>
Respond in plain text only. No markdown unless writing code.
</format>
Template filling. When you have a document template with placeholder variables, wrapping different sections in tags helps Claude understand the structure:
<template>
[HEADLINE]:
[SUBHEADLINE]:
[BODY]:
[CTA]:
</template>
<brief>
Write landing page copy for an AI writing tool targeting freelancers.
Headline under 8 words. Subheadline one sentence. Body 2 paragraphs.
CTA: action verb + benefit.
</brief>
What XML tags don't fix
XML tags improve structural parsing — they don't make the model smarter or more accurate on factual tasks. They're most useful for format-sensitive, structure-dependent tasks where the model needs to clearly distinguish between different sections of a prompt.
For simple questions or straightforward requests, XML tags add overhead without meaningful benefit. Use them when prompt structure complexity warrants it, not everywhere.
GPT-5.5 and Gemini
GPT-5.5 and Gemini can use XML tags and parse them reasonably well, but they weren't as specifically trained on XML-structured data as Claude. For these models, markdown headers and clear plain-text structure often work just as well. If you use multiple models, using XML tags in Claude-specific prompts and markdown in others is a reasonable differentiation.