Lesson 12 of 2116
Claude's XML Tag Superpower
Claude was trained heavily with XML-tagged examples. Using tags to separate inputs, instructions, and expected outputs is one of the highest-leverage Claude-specific techniques.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1Why XML beats plain prose with Claude
- 2XML tags
- 3Claude-specific
- 4prompt structure
Concept cluster
Terms to connect while reading
Section 1
Why XML beats plain prose with Claude
Claude's training data included enormous amounts of XML-structured content. As a result, Claude treats XML tags as strong semantic signals — far more reliably than quotes, dashes, or 'the following article'. Tags also make your prompts self-documenting and easy to update programmatically.
A canonical tagged prompt
A tagged prompt with role, task, rules, input, examples, and required output shape — all cleanly separated.
<role>
You are a senior editor at a reputable science magazine.
</role>
<task>
Review the draft below and suggest improvements for clarity and accuracy.
</task>
<style_guide>
- Prefer active voice.
- Define technical terms on first use.
- No clickbait.
- Maximum 600 words.
</style_guide>
<draft>
{USER_DRAFT}
</draft>
<examples>
<example>
<input>A quantum leap is small.</input>
<suggested_edit>Explain that 'quantum leap' in physics means the smallest possible change — counterintuitive given the everyday meaning.</suggested_edit>
</example>
</examples>
<output_format>
Provide your response as:
<summary>One-sentence overall assessment.</summary>
<edits>
<edit location="paragraph 1">Suggestion.</edit>
<edit location="paragraph 2">Suggestion.</edit>
</edits>
<next_step>One sentence telling the author what to do first.</next_step>
</output_format>Tag naming conventions
- Use descriptive, lowercase names: <research_notes>, not <rn>.
- Be consistent within a prompt — don't switch between <doc> and <document>.
- Nest when semantically meaningful: <examples><example>...</example></examples>.
- Close every tag — Claude is forgiving but unclosed tags confuse it.
Output tags for parsing
If a downstream program will parse Claude's answer, require specific output tags. Then extract the content between them with a simple regex. This is more robust than JSON for long-form or mixed content.
Splitting internal reasoning from user-facing answer lets you hide 'thinking' from the end user while still logging it for analysis.
Respond with exactly these tags, in this order:
<thinking>
Your reasoning, step by step.
</thinking>
<answer>
The final user-facing answer.
</answer>
<confidence>
A number from 1 (uncertain) to 5 (certain).
</confidence>Hidden benefits
Compare the options
| Without XML tags | With XML tags |
|---|---|
| User draft blurs into instructions. | Clear semantic boundaries. |
| Hard to update programmatically. | Trivial to template: replace <draft>{TEXT}</draft>. |
| Output formatting is fuzzy. | Downstream parsing is reliable. |
| Claude occasionally confuses roles. | Claude respects labeled sections. |
Key terms in this lesson
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “Claude's XML Tag Superpower”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Creators · 38 min
Anthropic's Prompt Engineering Patterns
Anthropic publishes detailed prompt engineering guidance. Master the core patterns — Be Direct, Let Claude Think, and Chain Complex Prompts — to write production-grade prompts.
Creators · 40 min
Multi-Turn Reasoning: Agents That Think Across Steps
Some problems need more than one prompt. Learn how to design multi-turn reasoning flows — reflection, critique, retry — that give you AI which actually solves hard problems.
Creators · 36 min
Prefill Attacks and Defenses
An attacker can inject text that looks like part of the AI's own response, tricking it into behaviors it would otherwise refuse. Understand the attack vector and how to defend.
