<example> — when and how to use it in Claude prompts
Use one or more
A single input/output demonstration. Usually nested inside <examples>.
When to use <example>
- Few-shot prompting — showing the model 1–5 demonstrations before the live input.
- Anchoring an unusual output format that's hard to describe in prose.
When not to use it
- Don't use a single
<example>when zero-shot works — adding examples narrows the model's distribution and can hurt edge-case handling. - Don't put real user data in examples; the model may pattern-match and leak details.
Minimal example
<example>
<input>The food was cold and the waiter was rude.</input>
<output>negative</output>
</example>
Full example
<instructions>
Classify customer reviews as positive, neutral, or negative. Return only the label.
</instructions>
<examples>
<example>
<input>Loved the new menu, will be back!</input>
<output>positive</output>
</example>
<example>
<input>Service was okay, food was okay.</input>
<output>neutral</output>
</example>
<example>
<input>Waited 40 minutes for cold food.</input>
<output>negative</output>
</example>
</examples>
<review>{{ user_review }}</review>
Common mistakes
- Wrapping the I/O directly with no
<input>/<output>structure — Claude can usually figure it out, but the structured form is more reliable. - Making examples that don't span the real distribution (e.g., all positive). Examples set Claude's prior; skew them and outputs skew with them.
Cite this page
<example> — When and How to Use in Claude Prompts. claudexml.com. https://claudexml.com/tags/example/