<claudexml/>

Claude XML cheatsheet

One-screen condensed reference. Bookmark this.

Core tags

TagPurposeSibling of
<instructions>What the model should docontext, examples, documents, question
<context>Background facts (not commands)instructions, documents, question
<examples>Container for few-shot demosinstructions, question
<example>One demo (with <input>/<output>)nested in examples
<documents>Container for RAG passagesinstructions, question
<document>One passage (with <source>)nested in documents
<source>Citation ID for a documentnested in document
<thinking>CoT scratchpadanswer
<answer>Extractable final answerthinking
<format>Output schema / shapeinstructions, question
<role>Inline personastandalone

Recommended order

For prompts with long reference material:

<documents>...</documents>
<examples>...</examples>
<instructions>...</instructions>
<question>...</question>

For prompts without long material, instructions can come first.

Rules of thumb

  • Long documents → put them first.
  • Want to parse the output → wrap it in a tag and tell Claude "return only inside the tag."
  • Want citations → always include <source>.
  • Want reliability → 2–5 examples, not 0, not 20.
  • Want safety → sanitize user input before splicing into prompts.
  • Want structured output → use API tool use first; XML <format> second.

Extraction regex

To pull content from a tag:

<answer>([\s\S]*?)</answer>

Use the multi-line, non-greedy form in all languages. [\s\S] beats . because it matches newlines.

Cite this page
Claude XML Cheatsheet. claudexml.com. https://claudexml.com/cheatsheet/