Prompt Engineering
Beginner
4.5

Few-Shot Prompting Explained

Teach a model the exact format and style you want using a few examples.

0h 20m
1 lesson
1.2K students

What You'll Learn

Learning objectives will be added soon.

Tutorial Content

Why examples work

LLMs are, at heart, pattern matchers. When you describe what you want in words, the model has to interpret your description and hope it understood. When you show what you want with a couple of examples, it simply continues the pattern — far more reliably, and with far less explaining on your part. This technique is called few-shot prompting, and it's one of the highest-leverage tricks a beginner can learn.

The name refers to the number of examples: zero-shot (none, just instructions), one-shot (a single example), and few-shot (a handful).

Build a few-shot prompt

Suppose you want to pull structured data out of messy text. Instead of writing rules, show the pattern:

Extract the company and amount as JSON.

"Paid $40 to Netflix" -> {"company": "Netflix", "amount": 40}
"Spent 12.50 at Starbucks" -> {"company": "Starbucks", "amount": 12.5}
"Charged $99 by Adobe" ->

The model sees the input-to-output pattern and completes the last line with the correct JSON. You never had to explain "ignore the verb" or "amounts can be decimals" — the examples carry that knowledge.

When to reach for it

Few-shot shines whenever the result is easier to show than to describe:

  • A specific output format that's fiddly to spell out in words.
  • A particular tone or style you want matched.
  • Edge cases — include a tricky example and its correct answer so the model handles it.

Tips for good examples

  • Cover edge cases in your examples — decimals, missing values, unusual inputs — so the model learns the boundaries.
  • Keep formatting identical across every example; the model copies structure faithfully, including any inconsistency you leave in.
  • Use three to five examples. More rarely helps and just eats into your context budget.
  • Match the real mix — if many of your inputs have no amount, include an example with none.

A common pitfall

If the model keeps breaking format, your examples probably aren't consistent with each other. The model imitates exactly what it sees, so one sloppy example poisons the pattern. Clean up the examples before you add more instructions.

The takeaway

When you catch yourself writing "and if it's like X, do Y" for the third time, stop describing and start demonstrating. Two or three clean examples usually beat a paragraph of rules — and they're faster to write.

Try it now: Take a task where the model keeps drifting in format, give it three clean input/output examples followed by your real input, and watch it lock onto the shape you wanted.

Your Progress

Sign in to track your progress

Tags

Prompting
LLM