intermediateChapter 7 of 12

Using Examples (Few-Shot Prompting)

Few-shot prompting · Example selection · Format consistency through examples

Show, Don't Just Tell

Examples are one of the most reliable ways to steer Claude's output format, tone, and structure. A few well-crafted examples — known as few-shot prompting — can dramatically improve accuracy and consistency.

How to Structure Examples

Wrap examples in <example> tags so Claude can distinguish them from instructions:

Classify the email into a category. Here are some examples:

<example>
Email: "Do you ship internationally?"
Category: Pre-sale question
</example>

<example>
Email: "My order arrived broken."
Category: Broken or defective item
</example>

Now classify this email:
<email>{NEW_EMAIL}</email>

Best Practices

  • 3-5 examples hit the sweet spot for most tasks.
  • Make examples diverse — cover different categories, edge cases, and tones.
  • Make examples consistent — use the exact output format you want.
  • Wrap them in <example> tags so Claude knows they're demonstrations, not instructions.

Key Takeaways

  • Few-shot examples are the most reliable way to lock in a specific output format.
  • Diverse examples prevent Claude from overfitting to one pattern.
  • The format of your examples becomes the format of the output.

Exercises