Leaders Insights
Leaders Insights

Stay at the top of your field, a little every day.

DomainsMarketingDataFinanceAI
ResourcesLearnTestToolsBlogGlossary
© 2026 Leaders Insights — All rights reserved.
Tracks/AI Essentials/Prompt engineering/Prompting fundamentals/Few-shot prompting: teaching by example
2/3+140 XP

Prompting fundamentals

1Anatomy of a good prompt: role, context, task, constraints+1402Few-shot prompting: teaching by example+1403Asking for structured output: lists, tables, JSON+140

Few-shot prompting: teaching by example

# Few-shot promptingpromptingPrompt engineering is the practice of designing and refining text inputs to guide large language models toward accurate, relevant, and reliable outputs.View full definition →: 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.View full definition →: 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.

The problem with describing

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.

Teaching by example instead

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.

Why this works

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.View full definition → (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."

Choosing good examples

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.View full definition →"). Three tight examples beat ten rambling ones.

Running it with code

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.View full definition → (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.

python
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.View full definition → by hand right inside ChatGPT, Claude, or Gemini. Just paste your examples and your new message into the chat.

Few-shot beyond classification

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.View full definition → Explained" - youtube.com - a short, plain-language walkthrough of zero-shot vs few-shot with live examples you can copy]

Knowledge check

1. What best defines few-shot prompting?

2. According to the lesson, why do examples often work better than written rules for a task like classifying messages?

3. Why does few-shot prompting work so well with a large language model?

MULTIPLE CHOICE

4. Select ALL correct statements about the distinction between zero-shot, one-shot, and few-shot prompting.

Select all the correct answers.

MULTIPLE CHOICE

5. Select ALL practices the lesson recommends when writing few-shot examples.

Select all the correct answers.

When few-shot is overkill

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.View full definition → for few-shot when:

  • The format is specific and you want it exactly right every time.
  • The task has edge cases that rules struggle to capture.
  • You need consistency across many runs (like classifying a whole inbox).
  • The style or voice matters and is hard to describe.

Skip it when the task is common and obvious. Adding examples then just wastes space and your time.

A quick test

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.

Common Mistakes

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.

Try it yourself

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.

Key Takeaways

  • Show, don't tell. Two or three examples in a consistent format usually beat a paragraph of rules.
  • Your examples are your instructions. Cover the range, include a tricky case, and balance your labels so the model stays neutral.
  • Keep the format identical across every example: same labels, same spacing, same wording. Inconsistency confuses the model.
  • Try zero-shot first. Add examples only when the model drifts off format or misreads your intent.
  • Set temperature to 0 for classification and any task where you want the same answer every time.

What to do, from this lesson

These actions are compiled in the role's Playbook.

  • Provide two or three consistent worked examples for tricky formats
See the full action playbook →

Previous

Anatomy of a good prompt: role, context, task, constraints

Next

Asking for structured output: lists, tables, JSON