esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

How Do You Pick and Order Few-Shot Examples?

How to choose few-shot examples, why their order can change the answer, and when to pick them per question, for your AI interview.

In short

Pick few-shot examples from real past cases that look like the task and cover its odd cases, then keep one fixed format. Order matters too: models can lean toward answers near the end of the prompt, so mix the labels and test a few orders.

12 min readIntermediateCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Few-shot examples are solved cases you put in the prompt before the real input. I pick them from past cases with checked answers. They should look like the real job, cover the odd cases, and share one format. Then I order them so the answers mix, since order can change the result. I test two or three orders on cases I didn't use for picking, and I retest after any model change.

What is few-shot prompting, in plain words?

Few-shot prompting means you show the model a handful of solved examples before the real question. Each example is an input with the answer you want. Anthropic's prompting guide says a few well-crafted examples improve accuracy and consistency.

Picture a claims clerk on their first day. The manager hands over four past claims, each with its decision already written, and says to handle the next one the same way. The clerk copies the pattern. The examples teach the job faster than a long rule book does.

A typical case: an insurer could use a model to sort incoming claims into three piles, pay, ask for papers, or send to a person. Four examples in the prompt keep every answer in those three labels and in the same short format.

Key words

Few-shot
A prompt with a few worked examples before the real input. With no examples it is zero-shot.
Label
The answer an example shows, such as pay or ask for papers.
Answer bias
A model's lean toward answers that sit near the end of the prompt or are common in its training data.
Held-out cases
Past cases kept out of the picking, used only to test the finished prompt.

How do you pick the examples?

Start with real past cases that have a checked answer. Then pick by three tests: they look like the real task, they cover the odd cases, and they share one format. Anthropic's guide asks for the first two.

  • “Relevant: Mirror your actual use case closely.”

    Anthropic, prompting best practices

  • “Diverse: Cover edge cases and vary enough that Claude doesn't pick up unintended patterns.”

    Anthropic, prompting best practices

From past cases to the prompt

Labelled past cases

Real cases with the right answer

Pick

Same kind of case

Same fields and claim type

Odd cases too

Missing papers, fraud flags

3 to 5, ordered

Labels mixed, same format

Model

sees the examples, then the new case

Right label

checked on held-out cases

  1. 1Cases that look like the new claim are pulled out.
  2. 2Odd cases, such as a fraud flag, are pulled out too.
  3. 3The like-for-like cases move on to the order step.
  4. 4The odd cases move on to the same order step.
  5. 5The mixed set goes into the prompt before the new claim.
  6. 6The model's answer is checked on cases held back from picking.
Past cases with known answers are the pool. Choose the ones that look like the new case and cover its odd cases, then order them so the labels mix. The model reads them before the real input.

I give the odd cases the most weight. Four easy claims teach the easy path and nothing about a claim with a missing document or a fraud flag, so the set needs at least one of each odd case that matters for the job.

Keep the count small. Anthropic's guide says "Include 3-5 examples for best results." More examples cost more tokens on every call, and a long run of one pattern can make the model copy it.

Wrap each example in tags such as <example>, so the model can tell examples from instructions. Anthropic's guide says to "Wrap examples in <example> tags" for that reason.

Worked example. A claims team has about 2,000 labelled claims from the last two years. For a motor claim with no repair estimate, they pick four: a clean payment, a missing estimate, a suspected fraud sent to a person, and a claim a person later overturned. Each has the same three fields and a one-line reason. The new claim goes after them. The numbers are made up for illustration.

Min and colleagues tested something useful. On a range of classification and multi-choice tasks, random labels barely hurt results. The authors named three key drivers: the label space, the distribution of the input text, and the overall format of the sequence. So I put my effort into those three. I still keep the answers correct, because a real task is judged on them.

Should the examples change with each question?

Usually a fixed set is the place to start. For a large, varied task, you can fetch the past cases most similar to each new input instead. Liu and colleagues did this with a search step in their 2021 tests, and found that the retrieved picks consistently outperform random picks.

The cost is testing. Every input now gets a different prompt, so you can't check one prompt once. You need a test set that covers the range of inputs, and you need to explain why the search picked a bad case.

Tip

Asked when to retrieve examples? Say you start with a fixed set, and move to per-question picks only when tests on your own cases show a gain.

Does the order of the examples matter?

Yes, sometimes a lot. Lu and colleagues found that the same examples in a different order could move a model from near state-of-the-art results to near random guessing.

Zhao and colleagues traced part of it to bias. In their 2021 tests on GPT-3 and GPT-2, the model leaned toward answers that sit near the end of the prompt, or answers common in its training data. So if every example ends in deny, the model may say deny more often than it should. Newer models may differ, so test your own.

  • “the order in which the samples are provided can make the difference between near state-of-the-art and random guess performance”

    Lu et al., ACL 2022

  • “those that are placed near the end of the prompt or are common in the pre-training data”

    Zhao et al., ICML 2021

A good order can also fail on another model. Lu and colleagues found that a good order for one model did not carry over to another.

  1. 1

    Mix the labels

    Don't stack one answer at the end. Take turns between labels so no answer comes in one block or sits last by habit.

  2. 2

    Test a few orders

    Try two or three orders on held-out past cases, and keep the one that scores best on them.

  3. 3

    Retest after a change

    A new model, or a new version of one, can change which order wins, so run the test again.

Here is the mixing step in plain Python. It takes the three closest past cases to a new claim, then takes turns between their labels. The word match is a stand-in for a real search.

Python
# A simplified picker: take the closest past cases, then take turns between their labels.
PAST_CASES = [
    {"text": "motor claim, repair estimate attached", "label": "pay"},
    {"text": "motor claim, repair estimate missing", "label": "ask for papers"},
    {"text": "motor claim, same plate in three claims", "label": "send to a person"},
    {"text": "motor claim, small scratch, clear photos", "label": "pay"},
    {"text": "home claim, flood, policy lapsed last week", "label": "send to a person"},
]
def similarity(a, b):  # share of words in common: a stand-in for a real search step
    wa, wb = set(a.replace(",", "").split()), set(b.replace(",", "").split())
    return len(wa & wb) / len(wa | wb)

def pick(query, k=3):
    return sorted(PAST_CASES, key=lambda c: similarity(query, c["text"]), reverse=True)[:k]

def mix(cases):
    groups = {}
    for c in cases:
        groups.setdefault(c["label"], []).append(c)
    mixed = []
    while groups:
        for label in list(groups):
            mixed.append(groups[label].pop(0))
            if not groups[label]:
                del groups[label]
    return mixed

for c in mix(pick("motor claim, repair estimate missing, car towed")):
    print(c["label"], "<-", c["text"])

Output

ask for papers <- motor claim, repair estimate missing
pay <- motor claim, repair estimate attached
pay <- motor claim, small scratch, clear photos

Tip

Asked how you would order examples? Don't say the most important one goes last. Say you mix the labels and measure a few orders on cases you held back.

How would you set up examples for a bank's fee assistant?

A bank's chat assistant answers fee questions from its own price list. A wrong fee answer costs money and trust. I would start with 40 past customer questions that agents answered and checked, and pick five across the fee types: card, overdraft, wire, foreign currency and account closure.

Each example would show the price list line it relied on, in one fixed format. I would mix the labels, test three orders against 100 held-out questions, and keep the best one. When a price changes, the examples change too, so they go under the same review as the price list. The numbers are made up for illustration.

What does the interviewer want to hear?

A strong answer covers

  • Real past cases with checked answers, not invented ones
  • Picks that match the task and cover the odd cases
  • One format for every example, usually three to five of them
  • Labels mixed, because order can swing the result
  • Orders tested on held-out cases, and retested after a model change
  • Per-question picks only when tests show they help

Common traps

  • Trap"More examples are always better."

    BetterPast a few, examples add cost and can overweight one pattern. Test the count the same way you test the order.

  • Trap"Put the most important example last."

    BetterThe last place has a pull of its own. Mix the labels and measure, instead of relying on position.

  • Trap"Just grab any examples from the docs."

    BetterPick real cases that look like the job, with checked answers, and cover the odd ones.

Can you spot the weak example set?

Which set would you ship?

Three candidate example sets for a claims triage prompt. Which one do you ship?

Quick check

You switch to a new model. What should you do with the example order?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q077Zero-shot vs few-shot prompting?12 min
  2. Q099Why use delimiters or XML tags?10 min
  3. Q100How do you test prompts systematically?12 min
  4. Q101What are prompt optimizers (e.g. DSPy)?Coming soon
  5. Q102Why do prompts break when you switch models?11 min

Learn it in depth

Last updated on 26 November 2026

Building an AI feature that needs consistent answers?

I design and build AI products and agents, the interface and the system behind it. Book a short call and tell me what you need.