AI Prompt Library

Create, optimize, transform, and share prompts

The complete platform for prompt engineering. Organize, optimize, and share your AI prompts with advanced tools designed for ChatGPT, Claude, and Gemini.

Get weekly prompt tips

Product

  • Library
  • Gallery
  • Tools
  • AI Search
  • Pricing
  • How it works

Explore

  • AI Prompts
  • Business
  • Writing
  • Use Cases
  • Blog

Company

  • Grow Online Digital

    167-169 Great Portland St
    London, W1W 5PF

  • Contact Us

© 2026 AI Prompt Library. All rights reserved.

Privacy Policy Terms of Service
AI Prompt Library
Blog/Claude XML Tags for Prompt Engineering: Complete Reference [2026]
Prompt EngineeringClaude AI10 min read·March 2026

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

Without XML tags
Analyze our Q4 sales data. We sell B2B software. Focus on enterprise deals. Give me a summary with recommendations.

Vague, flat, inconsistent results

With XML tags
<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

Build XML prompts faster
Use these tools to structure and refine your Claude prompts.
Prompt Improver →Technical Jargon Simplifier →Blog Post Outline →

Complete Tag Reference

Every XML tag Claude recognizes, with usage guidance and examples.

<task>Define what Claude should do
Use when: Every structured prompt — the single most important tag
<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
Use when: When Claude needs domain knowledge, business context, or situational details
<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
Use when: When you need Claude to follow specific rules or formatting
<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
Use when: When you need a specific style, format, or quality bar
<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
Use when: When you need domain-specific expertise or a particular communication style
<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
Use when: Complex logic, math, multi-step analysis, or decisions with tradeoffs
<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
Use when: When pasting articles, reports, code, or data for Claude to analyze
<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
Use when: When you need a specific structure like JSON, markdown tables, or custom formats
<output_format>
## [Section Title]
**Finding:** [one sentence]
**Evidence:** [data point]
**Action:** [recommendation]
</output_format>
<constraints>Define what Claude should NOT do
Use when: When you need to prevent common failure modes
<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
Use when: When the reading level, tone, or technical depth should match a specific audience
<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.

Data analysis with XML structure
<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>
Code review with XML tags
<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>
Content creation with examples
<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>
Decision analysis with thinking
<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>
Email drafting with constraints
<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>
Research synthesis
<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>
Meeting prep brief
<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>
Competitor analysis
<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

Do I have to use XML tags with Claude?
No. XML tags are optional but recommended for complex prompts. For simple questions, plain text works fine. XML tags help most when your prompt has multiple sections (context, task, constraints) or when you need consistent output formatting.
Does the order of XML tags matter?
Generally, put <role> and <context> first, then <task>, then <instructions> and <output_format>. Claude processes the full prompt before responding, but placing context before the task helps Claude understand what framework to apply.
Can I use custom tag names?
Yes. Claude understands any descriptive XML-style tag. <customer_data>, <financial_report>, or <meeting_notes> all work. Use names that clearly describe the content inside.
What is the difference between <thinking> tags and extended thinking?
Thinking tags are a prompting technique — you ask Claude to show reasoning in <thinking> tags in its output. Extended thinking is an API feature that enables deeper internal reasoning before responding. Thinking tags work everywhere; extended thinking requires API access.
Do XML tags work with ChatGPT and Gemini?
Partially. ChatGPT and Gemini can parse XML-structured prompts, but Claude was specifically designed to handle XML tags natively. For other models, markdown headers (## Task, ## Context) work better as structural separators.
How many tags should I use in one prompt?
Use as many as needed to separate distinct sections. A typical structured prompt uses 3-5 tags: <context>, <task>, <instructions>, and <output_format>. Avoid over-tagging — if a section is one sentence, it probably does not need its own tag.

More Claude Prompt Resources

Free Claude Prompt Library [2026]
100+ copy-paste Claude templates organized by category
Claude Thinking Prompts Guide
Master thinking tags for 40% better reasoning
100+ Best Claude AI Prompts [2026]
Comprehensive guide with examples and interactive tools
12 Advanced Prompt Engineering Techniques
Chain-of-thought, ReAct, meta-prompting, and more

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