Claude Tips mascot
Claude Tips & Tricks
Prompt Engineering beginner

Use Few-Shot Examples to Steer Output

Provide 3-5 concrete input/output examples in your prompt to get more accurate, consistent output from Claude.

Few-shot prompting means giving Claude concrete examples of desired input/output pairs. It’s one of the most reliable ways to control response quality.

<instructions>
Classify the customer message as one of: billing, technical, account, other.
Respond with JSON only.
</instructions>

<examples>
<example>
<input>I can't log into my account</input>
<output>{"category": "account"}</output>
</example>

<example>
<input>My invoice shows the wrong amount</input>
<output>{"category": "billing"}</output>
</example>

<example>
<input>The app crashes when I upload a file</input>
<output>{"category": "technical"}</output>
</example>
</examples>

<message>
I want to change my subscription plan
</message>

Why this works: Claude infers your desired format, length, tone, and classification logic from examples far more reliably than from lengthy written instructions alone. Three to five examples is the sweet spot, enough to establish a pattern without wasting tokens.

Pro tip: Include at least one edge case or ambiguous example to show Claude how you want those handled.

Paste into Claude Code
I need to create a prompt template with few-shot examples. Help me write 3-5 input/output examples for the task I'll describe, formatted with XML tags.