AI engineering / Beginner / 01.09
Zero-shot and few-shot
Ask a model with no examples, one example or a few, and learn how to pick examples that help and what they cost you.
13 min readFree
Asking with and without examples
The last lesson, System Prompting, ended with a promise: next, zero-shot and few-shot prompting, asking with and without examples. Here it is.
Picture a new helper at a small shop. You can say, "Sort the mail into piles: bills, bug reports and thank-you notes." Or you can say that, and also hand over three letters you already sorted. The second way takes a little longer, but the helper sees exactly what you mean. Models can work from both kinds of instruction.
By the end you will know what zero-shot, one-shot and few-shot prompts are, when each one fits, how to pick good examples, and what examples cost. You will run two small programs. Neither calls a real model.
Key words
- Prompt
- The text you send a model so it can reply.
- Shot
- One worked example placed inside a prompt. "Three shots" means three examples.
- Zero-shot prompting
- Asking with no examples: only the instruction and the new input.
- One-shot prompting
- Asking with exactly one worked example first.
- Few-shot prompting
- Asking with a small handful of worked examples first.
- Label
- The short answer you want back, such as billing or bug.
- In-context learning
- A model picking up a pattern from the text in your prompt, with no extra training.
Zero-shot: just ask
A zero-shot prompt has an instruction and the new input, and nothing else. "Translate this sentence into French." "Sort this message into billing, bug or praise." You count on the model to know the task already, from everything it read while it was built.
It is the shortest prompt you can write, so it is where you start. Send the plain ask, read the answer, and only add examples if the answer is not what you wanted.
The Prompt Engineering lesson already told you to give an example when you need an exact format. Zero-shot is what you do before that step, and few-shot is what you do after it.
Tip
Always write the zero-shot version first. It is your baseline. If examples do not beat it, you saved yourself the extra words.
Not the same as zero-shot learning
You may meet "zero-shot" in research too, and the meaning there is narrower. Wikipedia describes zero-shot learning as "a problem setup in machine learning where, at test time, a learner observes samples from classes which were not observed during training, and needs to predict their class". Its example: a model that knows horses, and also knows that zebras look like striped horses, can recognise a zebra it has never been shown.
Zero-shot prompting is the everyday cousin. It only says that your prompt holds no examples. Both ask a system to do something without being shown how, which is why they share a name. When someone talks about a chat prompt being zero-shot, they mean no examples in the prompt.
Few-Shot: show, then ask
A few-shot prompt puts a small set of worked examples in front of the real question. Each example is a pair: an input, and the answer you wanted for it. The model then reads your new input and continues the pattern.
The idea became famous through a 2020 paper titled "Language Models are Few-Shot Learners". Its abstract starts from a gap. The usual method needed "task-specific fine-tuning datasets of thousands or tens of thousands of examples", while "humans can generally perform a new language task from only a few examples or from simple instructions". Fine-tuning means training a model further on your own data.
The authors trained GPT-3, a model with 175 billion parameters (the numbers a model learns), and tested it in a few-shot setting. They report that scaling up language models "greatly improves task-agnostic, few-shot performance, sometimes even reaching competitiveness with prior state-of-the-art fine-tuning approaches".
The detail that matters for you is how the examples were given. The abstract says GPT-3 was applied "without any gradient updates or fine-tuning, with tasks and few-shot demonstrations specified purely via text interaction with the model". In plain words, nothing was retrained. The examples were typed into the prompt.
Wikipedia's page on prompt engineering names this ability: "A model's ability to temporarily learn from prompts is known as in-context learning." Note the word temporarily. The model does not keep what it picked up. Next time, the examples are gone unless you send them again. The page also says a prompt "may include a few examples for a model to learn from in-context, an implementation of few-shot learning for LLMs".
The same abstract is honest about limits. It says there are "some datasets where GPT-3's few-shot learning still struggles". Examples help. They are not magic.
One-shot, the middle case
One-shot sits between the other two: a single worked example, then your question. It is the smallest way to show a format. One example can show "answer with just the label" in a way that words alone may not.
The catch is that one example gives the model nothing to compare against. It cannot tell which parts of the example matter and which are accidents. If your one example is a short, angry message, the model might treat "short and angry" as part of the task. The Claude docs make a related point: examples should be diverse, so the model "doesn't pick up unintended patterns".
Zero-shot
No examples. Shortest prompt. Start here and check the answer.
One-shot
One example. Cheap way to fix the shape of the answer. Easy to copy by accident.
Few-shot
A handful of examples. Shows the pattern and the tricky cases. Longest prompt.
Building the three prompts
Let's build all three from one task. The program below takes a task, a list of labelled examples and a new message. It writes a prompt in a fixed shape: the task, then each example as a Message line and a Label line, then the new message with an empty Label line for the model to finish. It prints each prompt with a rough word count, using a plain split on spaces.
This program only builds text. It calls no model, no network and no paid service, so it runs free.
TASK = "Sort each support message into one label: billing, bug or praise."
EXAMPLES = [
("I was charged twice this month.", "billing"),
("The app crashes when I tap Save.", "bug"),
("Love the new look, great work!", "praise"),
]
def build_prompt(task, examples, new_message):
lines = [task, ""]
for message, label in examples:
lines.append("Message: " + message)
lines.append("Label: " + label)
lines.append("")
lines.append("Message: " + new_message)
lines.append("Label:")
return "\n".join(lines)
new_message = "My invoice shows the wrong amount."
for name, count in [("zero-shot", 0), ("one-shot", 1), ("three-shot", 3)]:
prompt = build_prompt(TASK, EXAMPLES[:count], new_message)
print("=== " + name + ": " + str(len(prompt.split())) + " words ===")
print(prompt)
print()Output
=== zero-shot: 19 words === Sort each support message into one label: billing, bug or praise. Message: My invoice shows the wrong amount. Label: === one-shot: 28 words === Sort each support message into one label: billing, bug or praise. Message: I was charged twice this month. Label: billing Message: My invoice shows the wrong amount. Label: === three-shot: 47 words === Sort each support message into one label: billing, bug or praise. Message: I was charged twice this month. Label: billing Message: The app crashes when I tap Save. Label: bug Message: Love the new look, great work! Label: praise Message: My invoice shows the wrong amount. Label:
Read the three counts: 19 words, 28 words and 47 words. The one-shot prompt adds a single example, 9 words. The three-shot prompt adds two more examples, 19 more words. The new message and the task never change. Only the examples grow.
Look at the shape too. Every example uses the same two lines, Message then Label. The last prompt line is "Label:" with nothing after it. That empty slot is the invitation: it shows the model exactly where its answer goes.
Picking good examples
The Claude docs page says examples are "one of the most reliable ways to steer Claude's output format, tone, and structure", and that "a few well-crafted examples (known as few-shot or multishot prompting) improve accuracy and consistency". It asks for three things from each set of examples: relevant, diverse and structured.
- 1
Mirror the real job
The docs call this relevant: examples should "mirror your actual use case closely". Use messages like the ones real users will send, not neat made-up ones.
- 2
Cover the tricky cases
The docs call this diverse: "cover edge cases and vary enough" that the model does not pick up unintended patterns. A message that is half billing and half bug is more teaching than a fourth easy one.
- 3
Keep the format identical
Every example should use the same labels, the same spelling and the same layout. The next section shows why.
- 4
Mix the labels
If all your examples have the same answer, the answer looks like part of the pattern. Include each label at least once. Our toy model below shows this problem in action.
- 5
Keep the examples apart from the instructions
The docs call this structured: wrap examples in tags so the model can tell them from instructions. A plain, repeated layout like ours does a similar job in a small prompt.
How many? The Claude docs say to "include 3–5 examples for best results". That is one vendor's advice for its own models, so treat it as a starting point and test your own task.
Quick check
Your three examples all have the label "bug". What is the risk?
Why the format must match
Now a toy test. The program below sends five prompts to a stand-in model and prints each reply.
Please read this part carefully: the stand-in is not a real model. It is a few lines that follow one rule. It looks for lines starting with "Label: " in the prompt and copies the last label it finds, exactly as written. If it finds none, it returns a fixed chatty sentence. That is it. I rigged it on purpose to make two points easy to see, and a real model is not this simple. A real model is slower, costs money for every token, can give a different answer each run, and can fail or refuse. This stand-in lets the code run free.
def build_prompt(task, examples, new_message):
lines = [task, ""]
for message, label in examples:
lines.append("Message: " + message)
lines.append("Label: " + label)
lines.append("")
lines.append("Message: " + new_message)
lines.append("Label:")
return "\n".join(lines)
def fake_model(prompt):
# Rigged: it copies the last label it saw, in the format it saw.
seen = [line[len("Label: "):] for line in prompt.split("\n")
if line.startswith("Label: ") and len(line) > len("Label: ")]
if seen:
return seen[-1]
return "Sure! That sounds like it could be a billing problem."
TASK = "Sort each support message into one label: billing, bug or praise."
new_message = "My invoice shows the wrong amount."
tidy = [("I was charged twice this month.", "billing"),
("The app crashes when I tap Save.", "bug"),
("Love the new look, great work!", "praise")]
reordered = [tidy[2], tidy[1], tidy[0]]
same_labels = [("I was charged twice.", "bug"),
("The app crashes on Save.", "bug"),
("Save does nothing.", "bug")]
messy = [("I was charged twice this month.", "Label - billing"),
("The app crashes when I tap Save.", "-> bug"),
("Love the new look, great work!", "PRAISE!!")]
cases = [("no examples", []),
("tidy examples, billing last", reordered),
("tidy examples, praise last", tidy),
("all examples say bug", same_labels),
("messy formats", messy)]
for name, examples in cases:
reply = fake_model(build_prompt(TASK, examples, new_message))
print(name + " -> " + reply)Output
no examples -> Sure! That sounds like it could be a billing problem. tidy examples, billing last -> billing tidy examples, praise last -> praise all examples say bug -> bug messy formats -> PRAISE!!
Go line by line. With no examples, the stand-in gives a chatty sentence, because nothing told it what shape to use. That is a zero-shot answer you could not feed straight into your code. With tidy examples, it answers with just a label, in the shape it saw. That is the whole value of a consistent format.
Next, order. With billing last, the reply is "billing". With praise last, the reply is "praise", though the message is about an invoice. The stand-in copies whatever came last. A real model is subtler than this, but the habit is real enough to guard against: do not end your examples with the same label every time, and do not put one label in a long run.
Then the two broken cases. When all examples say "bug", the reply is "bug". When the formats are messy, the reply is "PRAISE!!", a shape your code would not expect. The stand-in copies the mess it was shown. In the Wikipedia page on prompt engineering, one cited result shows that models can be sensitive to formatting: "Some studies have shown up to 76 accuracy points across formatting changes in few-shot settings."
Tip
Put your examples in one place in your code and build every prompt from it, as our builder does. Then the format cannot drift between examples.
What examples cost
Every example is more text, and models bill and limit by tokens, the small pieces text is cut into. Our counts are in words, which is a rough guide only. The Tokens lesson explains the real unit.
Here is a made-up sum. Suppose your app sends 10,000 requests a day. The three-shot prompt above is 28 words longer than the zero-shot one (47 minus 19). That is 280,000 extra words a day. If the made-up price were 1 dollar for every million words, the extra would be 28 cents a day. A real price will differ, and real services count tokens, so check the current price list. The point is how it grows: more examples times more requests.
Examples also take up room in the model's memory for one conversation. The Context Window lesson covers that limit. A long list of examples leaves less space for your user's real message.
Money
Every example is sent again with every request, so its cost repeats each time.
Room
Examples share the context window with the user's text and the model's reply.
Speed
A longer prompt has more for the model to read before it starts answering.
So the habit is simple. Start with zero-shot. Add one example if the format is wrong. Add more only for the tricky cases that still fail. Stop when the answers are good enough.
Quick check
Which order is best for a new task?
What to remember
Ask, then show
Zero-shot is no examples, one-shot is one, few-shot is a handful.
Pick with care
Cover tricky cases, keep the format identical, mix the labels.
Watch the cost
Examples are sent every time, so add only what earns its place.
Remember the limits too. Examples teach inside one prompt only, and they cannot promise a perfect answer. Test your prompt on real messages, the way the Prompt Engineering lesson showed.
Next: chain-of-thought, asking a model to work step by step.
Sources
Last updated on 16 November 2026
Learn with me
Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.