D4 · Prompt Engineering › Cluster 4 · Structure with XML Tags

4.2 · Common Tag Patterns

<document> · <instructions> · <example>

CONCEPT A small, reusable vocabulary of tags

Because no tag names are reserved (4.1), teams converge on a handful of conventional, descriptive tags simply because they read clearly. You don't have to use these exact names — but they're a solid default set, and staying close to convention makes prompts easier for humans to review too.

TagWhat it holds
<document> / <documents>Source material Claude should read — reports, transcripts, pasted text.
<instructions>The task itself: what Claude should do, step by step.
<example> / <examples>Few-shot demonstrations of the desired input→output behavior.
<context>Background the task depends on but that isn't the primary data.
<formatting>Rules for how the answer should be shaped/structured.
<input> / <query>The specific variable input or question for this call.
🔑 These are conventions, not keywords. <source_text> would work just as well as <document> — as long as you use it consistently.

CONCEPT Consistency + referencing the tag by name

Two habits turn a pile of tags into a reliable structure:

The instruction and the container share the same word. "Summarize the article in <document>" is unambiguous; "summarize the article" leaves Claude to hunt for it.

DIAGRAM A conventional prompt skeleton

flowchart TD P["Prompt"] --> C["<context>
background"] P --> D["<document>
source material"] P --> E["<example>
few-shot demo"] P --> F["<formatting>
output shape"] P --> I["<instructions>
the task — refers back to
<document> & <example> by name"] classDef data fill:#e7f0ff,stroke:#4a90d9,color:#123; classDef task fill:#d4edda,stroke:#28a745,color:#155724; class C,D,E,F data; class I task;

CODE A prompt built from conventional tags

Each content type gets its own tag, names stay consistent, and the <instructions> block refers to the other tags by name.

# System / user prompt content
<context>
You are reviewing support tickets for a SaaS billing product.
</context>

<example>
  Ticket: "Charged twice this month." → Category: billing_error; Priority: high
</example>

<document>
Ticket #4821: I was billed for the Pro plan but I'm on the Free tier.
</document>

<formatting>
Reply as JSON with keys: category, priority, one_line_summary.
</formatting>

<instructions>
Using the ticket in <document> and the pattern shown in <example>,
classify the ticket. Follow the shape in <formatting> exactly.
</instructions>
🔑 Notice how <instructions> names <document>, <example>, and <formatting> — the instruction is wired to exact regions, not to "the stuff above."

TRADE-OFFS House conventions vs. ad-hoc tags

✅ A shared tag vocabulary

  • Prompts across a team look and parse the same way
  • Templates and post-processing code can rely on stable names
  • Easier to review, diff, and hand off

⚠️ A new tag name every time

  • Maximum flexibility for a one-off
  • But: no shared parser, no muscle memory, easy to drift
  • Referencing "the text above" breaks when layout changes

EXAM TRAPS

Trap: "You must use <document>, <instructions>, <example> exactly." → These are common conventions, not required keywords. Any descriptive name works if used consistently.
Trap: Writing "use the text above" instead of naming the tag. → Refer to tags by name (e.g. "the article in <document>") so the instruction points at an exact region.
Trap: Mixing <doc> and <document> for the same content across calls. → Inconsistency undoes the benefit; pick one name and keep it.
Trap: Assuming <formatting> guarantees strict output. → It steers strongly, but for hard guarantees use prefill, structured outputs, or post-validation (covered elsewhere in D4).

PRACTICE

Q1 · Name four commonly used prompt tags and what each holds.

<document> — source material to read; <instructions> — the task; <example> — few-shot demonstrations; <formatting> — rules for the output shape. (<context> and <input>/<query> are also common.)

Q2 · Why refer to a tag by name inside the instructions?

It ties the instruction to an exact region of the prompt. "Summarize the article in <document>" removes any doubt about which text Claude should act on, versus a vague "summarize the article."

Q3 · Is <source_text> a valid substitute for <document>?

Yes. No tag names are reserved, so <source_text> is fine — provided it's descriptive and you use it consistently and reference it by that same name in the instructions.