Intermediate Prompting·Lesson 13

Few-Shot Prompting

Provide examples to teach the AI exactly what pattern you want it to follow.

Course progress13 / 29

What is Few-Shot Prompting?

Few-shot prompting means providing examples of the input-output pattern you want before giving the actual task. Instead of describing what you want, you show it.

Zero-shot: "Classify this review as positive or negative"
One-shot: "Example: 'Great product!' → Positive. Now classify: 'Terrible experience'"

Few-shot: Provide 3-5 examples before the actual task

Few-shot prompting is one of the most powerful techniques in prompt engineering. It works because the AI pattern-matches from your examples.

How to Structure Few-Shot Prompts

Follow this template:

```
I need you to [task description]. Here are some examples:

Input: [example 1 input]
Output: [example 1 output]

Input: [example 2 input]
Output: [example 2 output]

Input: [example 3 input]
Output: [example 3 output]

Now do the same for:
Input: [your actual input]

Output:

```

Key principles:
- Use 3-5 examples (diminishing returns after 5)

- Make examples representative of the variety you expect

- Include edge cases in your examples

- Keep formatting consistent across all examples

Practice This

Create a few-shot prompt that classifies customer support emails into categories: billing, technical, feature-request, and complaint. Provide 2 examples per category, then test with new emails.

Try this on ChatGPT, Claude, or Gemini

Key Takeaways
  • Few-shot prompting shows the AI what you want through examples
  • 3-5 examples is the sweet spot for most tasks
  • Include edge cases and variety in your examples
  • Consistent formatting across examples is critical

Test Yourself

Q1When should you use few-shot instead of zero-shot prompting?
When you need consistent output format, when the task is nuanced or ambiguous, or when describing the pattern is harder than showing it. Few-shot is especially useful for classification, formatting, and style-matching tasks.