Claude XML Tags for Prompt Engineering: Complete Reference
XML tags are the single biggest upgrade you can make to your Claude prompts. They turn vague requests into structured instructions that produce consistent, high-quality output every time.
This reference covers every major XML tag, when to use each one, and 8 complete prompt templates you can copy and adapt.
Why XML Tags Work Better with Claude
Claude was specifically designed to parse XML-style tags. Unlike markdown headers or plain text separators, XML tags create unambiguous boundaries between sections of your prompt. The result:
Clearer instructions
Claude knows exactly where context ends and task begins
Consistent output
Output format tags produce the same structure every time
Better reasoning
Thinking tags improve accuracy on complex analysis by 30-40%
Before and After: XML Tags in Action
Analyze our Q4 sales data. We sell B2B software. Focus on enterprise deals. Give me a summary with recommendations.
Vague, flat, inconsistent results
<role>Senior sales analyst</role> <context> B2B SaaS company, enterprise segment. Q4 2025 data attached. </context> <task> Analyze Q4 deals and identify patterns. </task> <output_format> 1. Summary (3 sentences) 2. Top 3 patterns with evidence 3. Action items for Q1 </output_format>
Structured, specific, reproducible
Complete Tag Reference
Every XML tag Claude recognizes, with usage guidance and examples.
<task>Define what Claude should do<task> Analyze this quarterly sales data and identify the top 3 trends. For each trend, explain the cause and recommend one action. </task>
<context>Provide background information Claude needs<context> We are a B2B SaaS company selling project management software. Our main competitors are Asana and Monday.com. We launched a new enterprise tier last quarter. </context>
<instructions>Specify constraints, rules, and output requirements<instructions> - Write in active voice - Keep each bullet under 20 words - Do not use jargon - Output as a numbered list </instructions>
<examples>Show Claude what good output looks like<examples> Input: "Our Q3 revenue grew 15%" Good output: "Revenue surged 15% in Q3, outpacing the 10% industry average." Bad output: "There was growth in Q3." </examples>
<role>Set Claude's persona and expertise level<role>Senior data analyst with 10 years of experience in retail analytics. You explain findings to non-technical executives.</role>
<thinking>Ask Claude to reason step-by-step before answering<task>Should we expand into the UK market?</task> <thinking> Consider: market size, competition, regulatory requirements, currency risk, and our current runway. </thinking>
<document>Wrap source material Claude should reference<document name="Q4 Report"> [paste your document content here] </document> <task>Summarize the key findings from this report in 5 bullets.</task>
<output_format>Define exactly how the response should be structured<output_format> ## [Section Title] **Finding:** [one sentence] **Evidence:** [data point] **Action:** [recommendation] </output_format>
<constraints>Define what Claude should NOT do<constraints> - Do not make up statistics - Do not exceed 500 words - Do not use passive voice - If unsure, say "I don't have enough data" rather than guessing </constraints>
<audience>Specify who the output is for<audience>C-suite executives with no technical background. They have 2 minutes to read this.</audience>
How to Combine Tags: The Standard Structure
Most effective Claude prompts follow this order. You do not need every tag — use what your prompt requires.
<role>Who Claude should be</role> <context> Background information Claude needs </context> <task> What Claude should do (the core instruction) </task> <document> Any source material to reference </document> <examples> What good output looks like </examples> <instructions> Rules, constraints, and preferences </instructions> <output_format> Exact structure of the response </output_format>
8 Copy-Paste XML Prompt Templates
Ready-to-use templates. Replace the {{placeholders}} with your content.
<role>Data analyst</role>
<context>
{{background about your data and business}}
</context>
<task>
Analyze this data and provide actionable insights.
</task>
<document>
{{paste your data here}}
</document>
<output_format>
1. Executive summary (3 sentences)
2. Key metrics table (markdown)
3. Top 3 findings with evidence
4. Recommended actions
</output_format><role>Senior software engineer specializing in {{language}}</role>
<task>
Review this code for bugs, performance issues, and security vulnerabilities.
</task>
<document>
{{paste code here}}
</document>
<output_format>
For each issue:
- Severity: critical / warning / info
- Line: location
- Problem: what is wrong
- Fix: code snippet with the correction
</output_format>
<constraints>
- Only flag real issues, not style preferences
- Provide the exact fix, not just a description
</constraints><role>{{role, e.g. "B2B SaaS content writer"}}</role>
<context>
{{company info, product details, target audience}}
</context>
<task>
Write a {{content type}} about {{topic}}.
</task>
<examples>
Good headline: "How Stripe Cut Payment Failures by 30%"
Bad headline: "Payment Processing Solutions"
</examples>
<instructions>
- Hook in the first sentence
- One CTA at the end
- Under {{word_count}} words
- Active voice only
</instructions><context>
{{describe your situation and constraints}}
</context>
<task>
Evaluate these options and recommend the best path forward.
</task>
<options>
Option A: {{describe}}
Option B: {{describe}}
Option C: {{describe}}
</options>
<thinking>
For each option, analyze:
1. Cost (upfront and ongoing)
2. Timeline to results
3. Risk and mitigation
4. Long-term impact
Then compare and recommend.
</thinking>
<output_format>
| Criteria | Option A | Option B | Option C |
|----------|----------|----------|----------|
| Cost | | | |
| Timeline | | | |
| Risk | | | |
Recommendation: [choice] because [reason]
</output_format><role>Professional communicator</role>
<context>
{{relationship with recipient, previous interactions}}
</context>
<task>
Draft an email to {{recipient}} about {{subject}}.
</task>
<audience>{{who they are, their priorities}}</audience>
<instructions>
- Under 150 words
- One clear ask
- Friendly but professional tone
</instructions>
<constraints>
- No exclamation marks
- No "just following up" or "per my last email"
- No passive voice
</constraints><role>Research analyst</role>
<task>
Synthesize these sources into a briefing document.
</task>
<document name="Source 1">
{{paste source}}
</document>
<document name="Source 2">
{{paste source}}
</document>
<output_format>
1. Executive summary (3 sentences)
2. Key findings (5 bullets)
3. Where sources agree
4. Where sources contradict
5. Gaps in the research
6. Recommended next steps
</output_format>
<constraints>
- Cite which source supports each finding
- Flag any claims without evidence
</constraints><context>
Meeting: {{meeting name}}
Attendees: {{who}}
Objective: {{what you want to achieve}}
</context>
<task>
Prepare a meeting brief with agenda, talking points, and anticipated questions.
</task>
<output_format>
## Agenda (30 min)
- [time] [topic]
## Key Talking Points
1. [point] — supporting data: [data]
## Likely Questions & Answers
Q: [question]
A: [prepared response]
## Decision Needed
[what needs to be decided]
</output_format><role>Market analyst</role>
<context>
Our product: {{description}}
Our differentiator: {{what makes you unique}}
</context>
<task>
Analyze {{competitor}} and identify opportunities.
</task>
<instructions>
- Focus on actionable gaps, not general observations
- Compare on: pricing, features, positioning, content strategy
- End with 3 specific actions we can take
</instructions>
<output_format>
## Quick Summary
[2 sentences]
## Comparison Table
| Feature | Us | {{competitor}} |
|---------|----|-----------|
## Gaps We Can Exploit
1. [gap] → [action]
</output_format>Common XML Tag Mistakes
Over-tagging simple prompts
If your prompt is one sentence, you do not need XML tags. Tags add value when you have multiple distinct sections.
Putting the task inside context
Keep context and task separate. Context is background; task is the instruction. Mixing them confuses the priority.
Forgetting to close tags
Every <tag> needs a </tag>. Unclosed tags cause Claude to misinterpret where sections begin and end.
Contradicting instructions
If your instructions say "be concise" but your output format asks for detailed paragraphs, Claude gets conflicting signals.
FAQ
More Claude Prompt Resources
Get 10 Free AI Prompt Templates
Join 2,000+ professionals getting weekly prompt tips and templates. No spam, unsubscribe anytime.
Related Articles
AI Guides
100+ Best Claude AI Prompts — Free Templates & Examples (2026)
Browse 100+ Claude AI prompts with XML formatting and thinking tags. Free copy-paste templates for coding, writing, analysis, and research — from Anthropic's prompt library.
18 min read
AI Guides
Claude AI <thinking> Tags — 25+ Prompts & Chain-of-Thought Examples (2026)
Master Claude's <thinking> tags with 25+ copy-paste prompts. Thinking tags vs extended thinking explained, with before/after examples that improve reasoning by 40%.
12 min read
Education
How to Write Perfect Claude Prompts in 2026 | Step-by-Step Guide
Learn how to write effective Claude AI prompts with 7 proven principles, step-by-step examples, and common mistakes to avoid. Beginner to advanced guide.
16 min read