As your prompts get more complex — mixing instructions, examples, context, and user input — they become harder for the model to parse. XML tags solve this by giving each component a clear, unambiguous label.
This is one of the most powerful techniques documented in Anthropic's official Claude guidance, and it works exceptionally well across all major models.
The Problem: Ambiguous Prompt Structure
Consider this prompt:
You are a customer support agent. Here is our refund policy: Refunds are
accepted within 30 days with a receipt. Here is the customer message:
I bought a jacket 3 weeks ago and it ripped. Can I return it?
Respond professionally.
Where does the policy end? Where does the customer message begin? Where are the instructions vs. the data? The model has to figure this out — and sometimes gets it wrong, especially in longer, more complex prompts.
The Solution: XML Tags
XML tags act as clear labels for each section of your prompt:
You are a customer support agent. Respond to the customer message below
based on our refund policy.
<refund_policy>
Refunds are accepted within 30 days of purchase with a valid receipt.
Items must be unused and in original packaging. Digital products are non-refundable.
</refund_policy>
<customer_message>
I bought a jacket 3 weeks ago and it ripped at the seam. Can I return it?
</customer_message>
<instructions>
- Be empathetic and professional
- Clearly state whether they qualify for a refund
- If yes, explain the process in 2-3 steps
- Keep response under 100 words
</instructions>
Now there's zero ambiguity. The model knows exactly what's a policy, what's the customer input, and what the instructions are.
Core XML Tag Patterns
Separating instructions from data
<instructions>
Summarize the document below in 3 bullet points.
Each bullet should be one sentence and start with an action verb.
</instructions>
<document>
[paste long document here]
</document>
Labeling examples
<examples>
<example>
<input>The service was terrible and I waited an hour.</input>
<output>Negative</output>
</example>
<example>
<input>Quick delivery and great packaging!</input>
<output>Positive</output>
</example>
</examples>
<input>The product works but the instructions were confusing.</input>
Separating thinking from output
Analyze this business decision. First think through pros and cons in
a <thinking> block, then give your recommendation in a <recommendation> block.
Decision: Should we launch in Europe before Asia?
Multiple documents
<document id="1" title="Q3 Report">
[content]
</document>
<document id="2" title="Q4 Projections">
[content]
</document>
Compare the financial performance shown in both documents.
Beyond XML: Other Delimiter Styles
XML tags are the gold standard (especially for Claude), but other delimiters work well too:
Triple backticks — Great for separating code or pasted content:
Analyze the following text:
[paste text here]
Identify the main argument and 3 supporting points.
Triple quotes — Similar to backticks, works well in Python-style prompts:
Translate the following to French:
"""
Good morning! How are you today?
"""
Markdown headers — Good for structuring multi-section prompts:
## Context
You are a marketing analyst at a SaaS company.
## Task
Analyze the campaign data below and identify the 3 highest-performing channels.
## Data
[paste data]
## Output Format
Markdown table with columns: Channel | Spend | Conversions | ROI
Rule of thumb: Use XML tags for Claude, triple backticks for code-heavy prompts, headers for long structured prompts.
When to Use XML Tags
XML tags are most valuable when:
- Your prompt mixes multiple types of content (instructions + data + examples)
- You're passing long documents or lots of context
- You want the model to reference specific sections by name
- You're building a system prompt that will handle many different user inputs
- You need the model to output structured content in specific sections
For simple one-shot prompts ("translate this", "fix this bug"), XML is overkill.
Pro Tip: Reference Tags in Your Instructions
Once you've labelled something, you can refer to it by name:
<product_description>
EcoBottle Pro — a 32oz insulated water bottle with a lifetime warranty,
made from 100% recycled stainless steel.
</product_description>
<target_audience>
Environmentally-conscious athletes aged 25-40.
</target_audience>
Using only the information in <product_description>, write 3 ad headlines
tailored to the <target_audience>. Do not invent features not mentioned.
This is extremely powerful for grounding the model — it knows exactly where to look and what to ignore.
Key Takeaway
XML tags eliminate ambiguity in complex prompts. Use them whenever your prompt mixes instructions, data, examples, or context. They're especially powerful with Claude, but work well across all models. Start using them now and you'll immediately notice fewer "misread" prompts.
Next: Learn Chain of Thought Prompting — how to make AI models reason step-by-step for dramatically better results on complex tasks.