NOTE

Anthropic XML Tags Cheat Sheet

titleAnthropic XML Tags Cheat Sheet date2026-05-20 typepermanent aliases statusactive authorgpt-5.4 source[[lit-anthropic-prompt-engineering]]

Anthropic XML Tags Cheat Sheet

A compact reference for using XML-style prompt tags with Claude.

Canonical skeleton

<instructions>
State exactly what Claude should do.
</instructions>

<context>
Background facts, constraints, or domain assumptions.
</context>

<examples>
  <example>
    <input>Example input</input>
    <output>Example output</output>
  </example>
</examples>

<input>
The live task or source material.
</input>

Recommended tag roles

  • <instructions> — operative directions
  • <context> — non-operative background
  • <examples> — container for demonstrations
  • <example> — one demonstration pair or case
  • <input> — the live item Claude should process
  • <documents> / <document> — repeated source documents

The exact names are flexible. Anthropic's stable recommendation is to use descriptive tags consistently.

Good default patterns

Single task

<instructions>
Summarize the argument in 5 bullets.
</instructions>

<input>
...
</input>

Task with background constraints

<instructions>
Extract safety-relevant claims only.
</instructions>

<context>
Ignore marketing language and rhetorical flourishes.
</context>

<input>
...
</input>

Few-shot prompting

<instructions>
Rewrite each passage in plain language.
</instructions>

<examples>
  <example>
    <input>The physician commenced the procedure.</input>
    <output>The doctor began the procedure.</output>
  </example>
</examples>

<input>
The committee rendered its determination.
</input>

Multi-document prompting

<instructions>
Compare the documents and list disagreements.
</instructions>

<documents>
  <document index="1">
    ...
  </document>
  <document index="2">
    ...
  </document>
</documents>

Do / don't

Do

  • keep each region semantically distinct
  • use nested tags when the source material is naturally nested
  • separate examples from live input
  • keep tag names stable throughout the prompt

Don't

  • rely on tags to replace unclear instructions
  • mix demonstrations and live data in the same block
  • treat this as a strict parser contract
  • assume the prompt must be valid XML

Mental model

Think of XML tags here as legibility markup for the model, not as a machine-validated schema. The goal is to make prompt boundaries obvious so Claude does not confuse instructions, context, examples, and live input.

See also