Learn/Prompt Engineering/Advanced Patterns
9 of 18

Few-Shot Learning — Teach by Example

5 min read

Show, Don't Just Tell

Sometimes the best way to tell AI what you want is to show it examples. Instead of describing the format, tone, or style you want, give the AI 2-3 examples of exactly what good output looks like. The AI then replicates the pattern. This is called "few-shot learning" — and it's incredibly effective for tasks where describing what you want is harder than showing it.

It's like training a new employee. You could write a 5-page style guide, OR you could show them 3 examples of good work and say "like this." The second approach is faster and produces better results.

How Few-Shot Works

Your Prompt

Convert these customer reviews into one-line summaries with a sentiment score. Examples: Review: "The product arrived quickly and works great. Packaging could be better though." Summary: Fast delivery, great product, packaging needs improvement. [Sentiment: 4/5] Review: "Terrible experience. Broke after two days and customer service was unhelpful." Summary: Product broke quickly, poor customer service. [Sentiment: 1/5] Now do these: Review: "Love the design and it's super easy to use. A bit pricey but worth it for the quality." Review: "It's okay. Nothing special but it gets the job done. Delivery took forever though."

AI Response

Summary: Beautiful design, easy to use, premium pricing justified by quality. [Sentiment: 4/5] Summary: Functional but unremarkable product, very slow delivery. [Sentiment: 3/5]

Why this works: The 2 examples show the AI exactly what format to use, how long the summary should be, and how to calibrate the sentiment score. Without examples, you'd need a paragraph of instructions to get the same consistency.

When Few-Shot Is the Best Approach

1

Consistent formatting at scale

Processing dozens of items the same way — product descriptions, data categorization, review summaries, email responses. Show the pattern once, AI replicates it perfectly.

2

Matching a writing style

Paste 2-3 samples of your brand voice or personal writing style and say "write in this same style." Much more effective than trying to describe your tone in words.

3

Classification tasks

Categorizing items, tagging content, sorting data. Show examples of how you'd categorize a few items, then let AI do the rest.

4

When words fail you

Sometimes you know what good output looks like but can't articulate why. Just show examples and let the AI extract the pattern itself.

The magic number: 2-3 examples

Research shows that 2-3 examples is the sweet spot. One example might be too ambiguous — the AI might latch onto the wrong pattern. Five+ examples waste tokens without improving quality. Two to three examples give the AI enough to understand the pattern without overthinking it.

Pro Technique: Diverse Examples

Make your examples diverse — cover different cases and edge cases. If you only show positive examples, the AI won't know how to handle negative ones. If you only show short inputs, it won't know what to do with long ones. Good examples cover the range of what you expect.

Quick Check

You want the AI to categorize support tickets into urgency levels. What's the best prompting approach?

Key Takeaway

When describing what you want is hard, show 2-3 examples instead. Few-shot learning is the most effective technique for consistent formatting, style matching, and classification tasks.