Few-shot examples
Describing a format in words leaves gaps. Watch a prompt fail without examples, succeed with four varied ones, and then go quietly wrong when the examples are too alike.
9 minFree
- Build the prompt
- Generate
- Read the ticket
- Kitchen
Press Play to watch it run, or step through with ← →. Then switch to Practice and run it yourself.
You take orders for Amma's Tiffin, a home tiffin service in Chennai.
Turn the customer's WhatsApp message into one kitchen ticket.
The ticket has the quantity and item, lunch or dinner, the area
and any note, separated by bars.
Message: Need 4 sambar rice for the office, Guindy, lunch. Extra papad if possible.What came back
Nothing yet. Press Play.
Background: the idea in plain words
You often know exactly what a good answer looks like, and still find it hard to describe. Try explaining in words how your team writes a one-line order ticket. You will forget something: capital letters, the order of the parts, what to write when a detail is missing. The model fills each thing you forgot with a guess.
An example removes the guessing. An example here means a sample input together with the exact output you want for it. A prompt (the text you send to a model) that contains a few such examples is called a few-shot prompt. A prompt with no examples is called zero-shot.
Examples work because a model is very good at continuing a pattern. If it sees three messages, each followed by a ticket in the same layout, then the most natural thing to write after a fourth message is a fourth ticket in that layout. You do not have to name the rules. The examples carry them.
This strength is also the risk. The model cannot tell which parts of your examples you meant as the rule and which parts are accidents. It copies whatever repeats. If every example happens to be a lunch order, "lunch" starts to look like part of the pattern.
The running example is Amma's Tiffin, a home tiffin service in Chennai. Customers order on WhatsApp in their own words. The kitchen wants each order as one line, such as 2 x veg thali | lunch | Anna Nagar | less spicy, so that a small program can read it and put it on the kitchen board.
Press Play to watch the zero-shot prompt come back in the wrong layout. Then switch Try it to After: four varied examples, and finally to Edge case: examples that are too alike.
What to notice
- Words describe a format. An example fixes it. The zero-shot prompt named every part of the ticket and still got labels, capitals and a greeting it did not want. One finished ticket settles all of those details at once.
- The model copies what repeats. That is the whole mechanism. Keep the layout identical in every example (same labels, same spacing, same separators), because the layout is what you want copied.
- Vary everything that is not the rule. Different dishes, different areas, short and long messages. Then the only thing the examples share is the layout, and the model has nothing else to copy.
- Give the odd case its own example. The good prompt shows what to write when the customer gives no meal time. The copycat prompt has no such example, so the model invents "lunch", and the format check still passes.
- Examples cost tokens on every call. They are part of the prompt, so you send them and pay for them each time. Start with a few, and add one only when it fixes a mistake you have actually seen.
Go deeperHow many examples, and what the vendors say
The three big vendors agree that examples help and that they should be varied. They differ on how strongly to push them.
| Vendor guide | What it says about examples |
|---|---|
| Google (Gemini) | Recommends always including few-shot examples, and says prompts without them are likely to be less effective. Also warns that with too many examples the model may start to overfit to them. Gives no fixed number: you may need to experiment. |
| Anthropic (Claude) | Calls examples one of the most reliable ways to steer format, tone and structure. Suggests 3 to 5, and says to make them relevant, diverse and wrapped in <example> tags. |
| OpenAI | Says to show a diverse range of possible inputs with the desired outputs. For its reasoning models, the advice is to try zero-shot first and add examples only if needed. |
So there is no magic number. A sensible way to work: write the prompt with three or four varied examples, run it on real messages, and look at the failures. If a failure is a layout problem, check that your examples are consistent. If the model copied content, your examples are too alike.
Do not test on your examples A prompt will almost always handle the messages that are already inside it as examples. Test with messages the prompt has never seen. The lesson Testing prompts with evals shows how to keep a proper test set.
Go deeperExamples steer tone too
Format is the easy case to see, but examples steer tone and length in the same way. Suppose the tiffin service also wants the model to write replies to customers. "Be warm but brief" means different things to different people. Two or three real replies in the house style ("Sure ma, 2 veg thali for lunch tomorrow. Less spicy, noted.") show the length, the warmth and the wording better than a paragraph of adjectives.
The same caution applies. If all your sample replies start with "Sure ma", expect most replies to start with "Sure ma". If that is not what you want, vary the openings.
Go deeperKeeping examples apart from the task
A model must be able to tell where the examples end and the real input begins. The good prompt in this lesson does three things for that:
- It wraps the examples in
<examples>and<example>tags, as Anthropic's guide suggests, so they are not mistaken for instructions. - It writes the new message with the same labels as the examples (
Message:thenTicket:). - It ends with
Ticket:and nothing after it. Google's guide calls this a response prefix: you start the answer and the model completes it.
Tags and delimiters have their own lesson: Context, delimiters and order. For how examples sit beside the other parts of a prompt, see Prompt engineering patterns.
Go deeperWords to know
| Word | Meaning in simple words |
|---|---|
| Example (a "shot") | A sample input together with the exact output you want for it |
| Zero-shot | A prompt with no examples |
| Few-shot | A prompt with a few examples |
| Overfit | To stick too closely to the examples, and copy their content as well as their layout |
| Edge case | An unusual input, such as an order with no meal time |
| Response prefix | The first words of the answer, written by you at the end of the prompt for the model to continue |
Check your understanding
Sources: the official documentation
This lesson is based on the official documentation. Check it for the latest details.
Something wrong or unclear in this lesson? Tell us, it gets fixed.