Claude XML Tags for Long-Context Prompts
Claude XML tags are a prompt-structure convention, not a separate API feature. Anthropic recommends them because they make complex prompts easier for Claude to parse when instructions, examples, documents, tool rules, and user input are mixed together.
Use descriptive tags
Prefer tags that describe the role of the content:
<instructions>
Summarize the documents using only cited evidence.
</instructions>
<documents>
<document index="1">
<source>pricing-policy.md</source>
<document_content>...</document_content>
</document>
</documents>
<user_question>
Which plan should we recommend?
</user_question>
Put long documents before the final question
For long-context work, place the large documents near the top, then put instructions and the specific query after the evidence. Use document-level tags and source metadata so citations and comparisons are easier to produce.
Tag examples explicitly
When using few-shot prompting, wrap the full example set in <examples> and each example in <example>. This helps Claude distinguish examples from the live user input.
Do not treat tags as a security boundary
Tags reduce ambiguity, but they do not make untrusted content safe. A malicious webpage inside <document_content> can still contain instructions. Pair tags with retrieval trust labels, tool permissions, and approval gates.
Sources
- Anthropic prompting best practices: https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices