Claude XML is the convention of wrapping parts of a prompt in named XML-style tags — <instructions>, <context>, <example>, <document>, <thinking>, and similar — so Claude can reliably distinguish the role of each section. Claude was trained on prompts that use these tags, and Anthropic's current docs continue to recommend them for prompts mixing several types of content. They are not real XML, not validated, and not required. They're a convention worth using when there's structural ambiguity in a single prompt that the model has to resolve.
When XML actually helps
Anthropic's docs name the core case: prompts that mix instructions, context, examples, and variable inputs. Expanding on that, the practical list:
- Repeatable work at scale — the same prompt run against varying inputs.
- Structured output you'll parse — extraction, classification, anything downstream code consumes.
- Long mixed prompts — when system instructions, retrieved documents, examples, and a question are all in one message and need clear edges.
- Untrusted-input boundary — wrapping user data so injection attempts are more visible in logs.
- Multi-artifact outputs in one call — draft + critique + final; extract + validate + transform. Separate output tags make each piece parseable.
For the full list with the reasoning, see when XML helps (and doesn't).
When it's just noise
The site's opinion, not Anthropic's:
- Conversational chat. The session already tells the model who is talking.
- Single-shot creative writing or one-line lookups.
- Anywhere a current Claude API feature now does the job better:
tool use for structured output (stronger than
<format>+ "return only this"); the APIsystemparameter for persona (stronger than inline<role>); extended thinking for reasoning (use it OR a<thinking>tag, not both — they can fight each other).
Tags cost a few tokens and a little visual noise. Skip them when there's no structure to mark.
A 30-second starter
When you do need structure, the single most useful pattern is to separate instructions, context, and the question:
<instructions>
You are reviewing a customer support ticket. Classify the sentiment as
positive, neutral, or negative. Return only the label.
</instructions>
<ticket>
Hi — the new dashboard is so much faster. Thank you for shipping this.
</ticket>
Classify the sentiment of the ticket above.
Now scale the same idea up:
<instructions>...</instructions>
<context>
The user is a senior engineer asking about distributed systems.
Prefer technical depth over surface explanation.
</context>
<examples>
<example>
<input>What is a quorum?</input>
<output>A quorum is the minimum number of nodes that must agree...</output>
</example>
</examples>
<question>Explain the CAP theorem in 100 words.</question>
What to read next
Tag reference
Every common XML tag, when to use it, when not to, with copy-paste examples.
patternsPrompt patterns
Few-shot, chain-of-thought, structured output, RAG, multi-document, agentic tool use.
examplesWorking examples
Complete, runnable prompts you can paste into the Claude API or claude.ai.
avoidAnti-patterns
Mistakes that look fine but quietly degrade Claude's reliability.
honestyWhen XML helps (and doesn't)
The eight cases where XML pays for itself, and where it's just noise.
faqFAQ
Quick answers to the questions everyone asks first.
cheatsheetCheatsheet
One-screen condensed reference. Bookmark this.
Who this site is for
Developers writing Claude prompts in production code. Prompt engineers tuning system prompts. Researchers comparing prompting strategies. Anyone who has hit the wall where "just write better English" stops working.
Everything here is plain HTML, no tracking by default, no signup, no paywall. The full reference is also published as a single fetch at /llms-full.txt for LLM ingestion.
Claude XML — The Complete Guide to XML Prompting for Claude. claudexml.com. https://claudexml.com/