Prompt Engineering

Few-Shot Prompting Explained — Teaching AI With Examples

How showing an AI a few examples of what you want often works better than trying to explain it.

Scroll to start

Show, Don't Tell

Imagine teaching someone to play a card game. You could spend ten minutes explaining all the rules step by step. Or you could just play a few rounds and let them figure it out by watching. Few-shot prompting is like that — you give the AI a few examples of what you want, and it learns the pattern.

Instead of writing out a long explanation, you include 2 to 4 examples in your prompt. The AI looks at those examples, picks up the pattern, and applies it to new situations. This often works better than trying to describe exactly what you want in plain language.

Think of it like giving someone a fill-in-the-blank worksheet instead of a textbook chapter. The blanks tell them exactly what format and kind of answer you expect — no long explanation needed.

Why Examples Beat Instructions

Sometimes trying to explain something perfectly in words is really hard. Your instructions might be clear to you but off-base from what the AI expects. Or the AI might read your words one way when you meant another. Examples sidestep all that — the AI just follows the pattern.

Few-shot prompting is especially useful when you want answers in a specific format, style, or structure. If you want haiku poems, give two or three examples of haiku. If you want code with error handling, show an example that includes error handling. The AI picks up on details you might forget to mention in words.

💡 Key Insight

A single good example can teach an AI more than a paragraph of instructions. Examples carry the shape, tone, and structure of what you want all at once — things that are hard to describe in words alone.

The Three-Step Method

Here's how to write a few-shot prompt in three simple steps:

1

Pick 2 to 4 Examples

Choose examples that show exactly the kind of input and output you want. Make sure each example shows the pattern clearly and consistently.

2

Label Each Example

Format your examples so the AI knows which is input and which is output. A common way is to use "Input:" and "Output:" labels, or "User:" and "Assistant:" labels.

3

Add Your New Input

After the examples, add the new question or prompt you want the AI to answer. The AI will apply the same pattern it learned from the examples.

Getting the Right Format

Let's say you want the AI to take a list of words and return each word backwards. Here's a prompt using few-shot prompting:

Few-shot prompt
// Three examples showing the pattern
Input: apple
Output: elppa

Input: robot
Output: tobor

Input: pizza
Output: azzip

// Your new input — AI will apply the pattern
Input: water
Output:

The AI reads the three examples, understands that you want each word spelled backwards, and applies that to the new word "water" — giving you "retaw".

Knowledge Check

Test what you learned with this quick quiz.

Quick Quiz — 3 Questions

Question 1
What is few-shot prompting?
Question 2
How many examples usually work best for few-shot prompting?
Question 3
Why is few-shot prompting sometimes better than plain instructions?
🏆

You crushed it!

Perfect score on this module.