Shaping the request · Lesson 4 of 8
Few-shot prompting
Show the AI a few worked examples so it can match a pattern, format or tone that's hard to describe in words.
You're learning as a guest — everything is open. Sign in to save progress, earn XP and pick up where you left off.
Show, don't just tell
Few-shot prompting means including a small number of examples — usually two to five — of inputs paired with the outputs you want, then giving the AI a new input to handle the same way. Instead of describing the pattern, you demonstrate it.
Language models are very good at continuing patterns. When a prompt contains several input→output pairs, the model infers the rule connecting them — the format, length, tone, level of detail — and applies it to the next input. This is sometimes called in-context learning: the model isn't permanently retrained; it just picks up the pattern from what's in front of it for this response.
A simple example
Say you want short, punchy product taglines in a specific style. Describing that style is surprisingly hard. Showing it is easy.
Write a tagline for a reusable water bottle. Make it punchy and clever, kind of playful but not cheesy.
Write a tagline for the last product, in the same style as the examples. Product: Noise-cancelling headphones Tagline: Your commute, on mute. Product: Slow cooker Tagline: Dinner that makes itself at home. Product: Ergonomic office chair Tagline: Sit like you mean it. Product: Reusable water bottle Tagline:
The second prompt never says "short," "wordplay" or "under six words," yet the examples communicate all of that. The response is an illustrative one — you'd likely get a different but similar tagline each time.
The anatomy of a few-shot prompt
- A brief instruction — what the task is. Examples work best with a sentence of guidance, not instead of it.
- Examples in a consistent format — the same labels ("Product:", "Tagline:") and layout every time.
- The new input — formatted exactly like the examples, with the output slot left open.
Consistency matters. If one example uses "Input/Output" and another uses "Q/A," the model has to guess which format to follow.
Convert each casual note into a clear, professional status update for my manager. Note: finished the slides lol, waiting on Sam for numbers Update: The presentation slides are complete. I'm waiting on Sam for the final figures and will add them as soon as they arrive. Note: client call moved again?? now thurs Update: The client call has been rescheduled to Thursday. I'll send an updated agenda beforehand. Note: bug fixed i think, need to test more tmrw Update:
When few-shot is worth it
Reach for examples when:
- Format must be exact — a specific JSON shape, a CSV row, a fixed template.
- Style is hard to describe — brand voice, humour, a particular writing rhythm.
- Labels are subjective — what counts as "urgent" in your support queue.
- You need consistency — processing many items the same way.
For everyday tasks the model already understands, zero-shot is usually enough. Examples cost extra words and can introduce their own problems.
How many examples?
Often two or three are enough to establish a pattern. Add more when the task has several distinct cases you need to cover (for example, one example per category in a classification task). Beyond that, returns tend to diminish, and very long example lists make the prompt harder to maintain.
Watch out: The AI may copy surface features of your examples — their length, sentence structure, even specific words — more than you intended. If every example starts with "Great news!", expect the output to as well. The next lesson covers how to choose examples that avoid this.
Tip: Combine few-shot with a clear instruction. "Write in the same style as the examples" or "Match the format exactly" tells the model why the examples are there.
Few-shot in a conversation
You don't always need to pack examples into one message. You can also correct the AI mid-conversation: "That's close — here are two I liked better: ..." This works similarly, though a single, well-structured prompt is easier to reuse and share.
Common mistakes
Mistake: Formatting examples inconsistently.
Fix: Use identical labels and layout for every example and for the final input.
Mistake: Using examples for tasks a plain instruction would handle.
Fix: Start zero-shot; add examples when you see a specific gap in format or style.
Mistake: Giving examples with no instruction at all.
Fix: Add a one-line task description, such as "Match the style of these examples."
Practice exercise
Teach a format by example
You keep a recipe notebook and want every recipe summarised as a single line in the form Dish | Time | Difficulty | Key ingredient. Write a few-shot prompt with at least two examples, then leave a slot for a new recipe.
Your draft stays in this browser tab — it isn't sent anywhere.Try your draft in the Playground
Hints
You can do the whole exercise as a guest.Sign in to save progress
Knowledge check