CONCEPT Structure so Claude can tell examples from instructions
The third pillar of good examples (alongside relevant and diverse, from 3.2) is structured.
Anthropic's guidance: wrap each example in <example> tags, and wrap multiple
examples in <examples> tags, so Claude can cleanly distinguish the examples
from your instructions. Without that boundary, a model can mistake a demonstration for a directive — or
blur the line between the sample inputs and the real one it's supposed to answer.
<example> per demonstration, <examples> around the
whole set. XML tags give Claude an unambiguous parse of "this is a sample, that is the task."Inside each example, tag the parts too. Use descriptive tags for the input and the expected output
(<input>/<output>, or domain names like
<ticket>/<urgency>). This nesting mirrors the general XML-structuring
practice (Cluster 4): consistent, descriptive tag names, nested when content has a natural hierarchy.
<urgency> tags, Claude will tend to return its answer that way too — a
useful lever, but be deliberate about it.| Element | Tag | Purpose |
|---|---|---|
| The whole set | <examples> | Marks the block as demonstrations, not instructions |
| One demonstration | <example> | Isolates a single input→output pair |
| Sample input | <input> / domain tag | Shows the shape of what comes in |
| Expected output | <output> / domain tag | Shows the shape you want back |
DIAGRAM The tag hierarchy
(plain / own tags)"] P --> EXS["<examples>"] P --> TASK["Real input
(the actual task)"] EXS --> E1["<example>
input → output"] EXS --> E2["<example>
input → output"] EXS --> E3["<example>
input → output"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; class EXS ok; class TASK gate;
CODE Tagged, consistent example blocks
Each demonstration wrapped in <example>, the set wrapped in
<examples>, inner parts tagged identically across all three. The real input sits
outside the examples block so Claude never confuses it for a sample.
system = """Rewrite each customer message in a warm, concise support voice. Follow the format shown in the examples exactly.""" user = """<examples> <example> <input>my order still hasnt shipped what is going on</input> <output>Hi! I'm sorry for the wait — let me check on your order's status right away.</output> </example> <example> <input>the discount code didnt work at checkout</input> <output>Thanks for flagging this! Let's get that code applied and sorted for you.</output> </example> </examples> <input>i was charged twice for one order</input>""" message = client.messages.create( model="claude-opus-4-8", max_tokens=16000, system=system, messages=[{"role": "user", "content": user}], ) # Claude parses the tags, matches the demonstrated tone + shape, answers the real <input>.
Rewrite warmly. Example: "my order..." → "Hi! I'm sorry..." "the code didnt work" → "Thanks!..."
now do: i was charged twice — Claude may treat a sample as the task, or blur where the demonstrations
end.TRADE-OFFS Tagged vs. loose examples
✅ Wrapped in <example>/<examples>
- Unambiguous: sample vs. instruction vs. real input
- Consistent inner tags → reliable pattern generalization
- Demonstrated output tags steer the return format
- Easy to add/remove examples cleanly
⚠️ Loose / inline examples
- Model can mistake a demo for a directive
- Boundary between samples and the real input blurs
- Inconsistent formatting confuses the pattern
- Slightly fewer tokens — rarely worth the ambiguity
EXAM TRAPS
<example> tags (and <examples> around
multiples) so Claude reliably distinguishes examples from instructions.<examples> block. → Put
the actual task outside the examples so it isn't mistaken for another sample.PRACTICE
Q1 · Which tags does Anthropic recommend for examples, and why?
Wrap each demonstration in <example> and the whole set in
<examples>. The tags let Claude distinguish the examples from your instructions
(and from the real input), so it treats them as patterns to follow rather than directives to obey.
Q2 · Why must all examples share the same inner structure?
Consistent formatting is what lets Claude generalize the pattern. If examples use different tags or shapes, Claude gets a mixed signal about the intended format — inconsistent example formatting confuses the model.
Q3 · Where should the real input go relative to the examples block?
Outside the <examples> block — as the actual task. Placing it
inside risks Claude treating it as one more demonstration instead of the input to answer.