# Few-shot promptingpromptingPrompt engineering is the practice of designing and refining text inputs to guide large language models toward accurate, relevant, and reliable outputs.Voir la définition complète →: teaching by example
You can write three sentences trying to explain what "urgent" means, or you can show the model three messages and let it figure out the pattern itself. The second approach almost always wins.
That is few-shot promptingpromptingPrompt engineering is the practice of designing and refining text inputs to guide large language models toward accurate, relevant, and reliable outputs.Voir la définition complète →: giving the model a handful of worked examples before asking it to do the real task. "Shot" just means "example." Zero-shot is no examples. One-shot is one. Few-shot is two or more.
Imagine you want to sort incoming customer messages into "urgent" or "normal." Your first instinct is to describe the rules:
> Classify this message as urgent or normal. Urgent means the customer is angry, mentions money being lost, has a deadline, or is threatening to cancel. Normal means general questions, feedback, or anything that can wait.
This works okay. But you will spend ages adding edge cases. What about a calm message that says "my payment failed"? What about an excited message that is actually fine?
Words about rules are slippery. Examples are sharp.
Here is the same task as a few-shot prompt. Notice there are no rules at all, just three examples and then the new message:
Classify each message as "urgent" or "normal".
Message: "My account got charged twice and the payment is for $4,000. I need this fixed today."
Label: urgent
Message: "Hi! Just wondering what your office hours are over the holidays."
Label: normal
Message: "This is the third time I've emailed. If I don't hear back I'm cancelling my subscription tomorrow."
Label: urgent
Message: "Loving the new dashboard, the charts are really clear."
Label:The model reads the pattern and completes the last line: normal.
It learned from your examples that double charges and cancellation threats are urgent, while friendly questions and praise are normal. You never wrote those rules down. The examples carried them.
A large language modellarge language modelA Large Language Model is an AI system trained on vast text data to predict and generate language, enabling tasks like writing, summarizing, and answering questions.Voir la définition complète → (the AI behind ChatGPT, Claude, and Gemini) is a pattern-completion engine. When it sees a clear, repeated structure, it continues that structure. Three examples in the same format create a strong pattern. The model copies the format and the logic baked into your choices.
This is why format matters as much as content. Keep every example identical in shape: same labels, same spacing, same wording for "Message" and "Label."
Your examples are your instructions. Pick them carefully.
Cover the range. Include the obvious cases and one tricky one. If a calm message can still be urgent (like a quiet "my payment failed"), make one of your examples exactly that. The model learns your edge cases from the examples you choose.
Balance your labels. If all three examples are "urgent," the model leans toward calling everything urgent. Mix them: two of one, one of the other, or an even split.
Be consistent. Use the exact same label words every time. "urgent" and "Urgent" and "URGENT" look like three different categories to a literal machine. Pick one.
Keep them short. Examples eat into the space the model can read at once (its "context windowcontext windowThe context window is the maximum amount of text (measured in tokens) a language model can process at once, including both the input prompt and the generated output.Voir la définition complète →"). Three tight examples beat ten rambling ones.
If you want to classify hundreds of messages, you will run this through an APIAPIApplication Programming Interface: a standardised interface that lets applications communicate and exchange data without knowing each other's internal workings.Voir la définition complète → (a way for your code to talk to the model). Here is a short, runnable example using OpenAI's Python library. The same idea works with Claude or Gemini, just different library names.
from openai import OpenAI
client = OpenAI()
few_shot = """Classify each message as "urgent" or "normal".
Message: "My account got charged twice for $4,000. Fix this today."
Label: urgent
Message: "What are your holiday office hours?"
Label: normal
Message: "Third email. Reply or I'm cancelling tomorrow."
Label: urgent
Message: "{new_message}"
Label:"""
def classify(message):
prompt = few_shot.format(new_message=message)
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[{"role": "user", "content": prompt}],
temperature=0,
)
return response.choices[0].message.content.strip()
print(classify("The app keeps crashing every time I try to pay."))One detail worth knowing: temperature=0. Temperature controls randomness. For classification you want the same answer every time, so set it to 0 for the most consistent, predictable output.
If you are not a coder, you do not need this. You can do few-shot promptingpromptingPrompt engineering is the practice of designing and refining text inputs to guide large language models toward accurate, relevant, and reliable outputs.Voir la définition complète → by hand right inside ChatGPT, Claude, or Gemini. Just paste your examples and your new message into the chat.
This trick is not only for sorting things. Use it any time you want a specific format or style.
Formatting data. Show two examples of turning a messy address into clean fields, and the model will do the rest.
Matching a tone. Paste two of your own past emails as examples, then ask the model to write a third in the same voice. It copies your style far better than if you described it.
Extracting information. Give two examples of pulling the name, date, and amount out of an invoice, and the model learns exactly which fields you want and how to lay them out.
The principle is always the same: stop describing, start demonstrating.
For a deeper, well-written reference on this and related techniques, the open Prompt Engineering Guide is free and stays current.
🎬 [VIDEO: "Few-Shot PromptingPromptingPrompt engineering is the practice of designing and refining text inputs to guide large language models toward accurate, relevant, and reliable outputs.Voir la définition complète → Explained" - youtube.com - a short, plain-language walkthrough of zero-shot vs few-shot with live examples you can copy]
Vérification des acquis
1. In few-shot prompting terminology, what does the word "shot" refer to?
2. According to the lesson, what is the main weakness of describing rules in words rather than showing examples?
3. In the urgent/normal classification example, how did the model know to label the final praise message as "normal"?
4. Select ALL correct answers about the shot-counting terminology described in the lesson.
Sélectionnez toutes les réponses correctes.
5. Select ALL correct answers about why the few-shot approach worked in the urgent/normal example.
Sélectionnez toutes les réponses correctes.
Few-shot is powerful, but it is not always needed. Modern models in 2026 are strong enough that simple tasks often work zero-shot, with no examples at all. "Summarize this in one sentence" needs no demonstration.
ReachReachThe number of unique people exposed to your message in a given period. Unlike impressions, reach counts each person once, no matter how often they see it.Voir la définition complète → for few-shot when:
Skip it when the task is common and obvious. Adding examples then just wastes space and your time.
Not sure if you need examples? Try zero-shot first. If the model gets it right, you are done. If it drifts off format or misreads your intent, add two or three examples to pin it down. Few-shot is your fix when zero-shot is close but not reliable.
Inconsistent examples. If one example uses "urgent" and another uses "high priority," the model gets confused about your categories. Match them exactly.
Too few examples for a hard task. One example might not show the pattern clearly. If results are shaky, add a second and third before doing anything fancier.
Leaking the answer. When testing, do not accidentally include the correct label on your new message. Leave the final Label: empty so the model fills it.
Unbalanced examples nudging the model. Three "urgent" examples in a row teach the model that urgent is the default. Mix your labels to keep it neutral.
Open ChatGPT, Claude, or Gemini right now. Paste this:
Turn each phrase into a polite, professional sentence.
Phrase: "send me the file"
Sentence: "Could you please send me the file when you have a moment?"
Phrase: "you're late"
Sentence: "I wanted to gently flag that the deadline has passed."
Phrase: "fix the bug"
Sentence:Watch it match the tone of your two examples. Then change the examples to be casual and funny, and run it again. The output changes to match. That is you teaching by example in under a minute.