# 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.

AI and LLM interview question Q098, Prompt and context engineering. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-pick-and-order-few-shot-examples

## Say it in 30 seconds

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.

## Say it in 2 minutes

Few-shot prompting means showing the model a few solved examples before the real question. Each one is an input with the answer you want, so the model copies the pattern instead of guessing the format. The hard part is choosing the examples and their order, because both change the result.

For picking, I start with real past cases that have a checked answer. I don't invent them. I want them to look like the job, so a motor claim with a missing repair estimate gets examples with missing estimates. I also want the odd cases covered, like a suspected fraud or a claim a person later overturned, because a set of easy cases teaches nothing about the hard ones. I keep the count at three to five, all in one format.

For order, I test rather than guess. Lu and colleagues showed that the same examples in a different order can swing a model from near state-of-the-art results to near random guessing. Zhao and colleagues found, in their 2021 tests on GPT-3 and GPT-2, that the model leaned toward answers near the end of the prompt. So I mix the labels, test two or three orders on held-out cases, and retest after a model change.

Last, I say what I don't know. Liu and colleagues compared retrieved picks with random picks, not with a fixed set. Whether per-question picks beat my fixed set is a question for my own tests. A fixed set is easier to test, and in a real product that matters more.

## 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.

- **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)

*Diagram, From past cases to the prompt: 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.*
1. Cases that look like the new claim are pulled out.
2. Odd cases, such as a fraud flag, are pulled out too.
3. The like-for-like cases move on to the order step.
4. The odd cases move on to the same order step.
5. The mixed set goes into the prompt before the new claim.
6. The model's answer is checked on cases held back from picking.

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. **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. **Test a few orders:** Try two or three orders on held-out past cases, and keep the one that scores best on them.
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:

```text
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." Better: Past 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." Better: The 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." Better: Pick 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?

A. Four motor claims, all paid in full, all labelled pay, from one branch
B. Four claims: a clean pay, a missing estimate, a fraud check, an overturned claim
C. Ten motor claims, all paid, from one city branch

**Answer:** B. It covers the odd cases and mixes the labels. The other two teach one narrow pattern, and the model would copy it.

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

A. Keep it, since order does not change results
B. Retest it on held-out cases, since a good order may not carry over
C. Put the newest example last
D. Drop the examples and add a longer system prompt

**Answer:** B. A good order for one model may not carry over to another. Only a test on held-out cases tells you.

## Can you answer these from memory?

**Flash cards**

- **What is few-shot prompting?** Putting a few solved examples in the prompt before the real input.
- **How many examples does Anthropic suggest?** Three to five, for best results.
- **What is answer bias here?** A lean toward answers that sit near the end of the prompt.
- **Why test several orders?** The same examples in another order can change the result a lot.
- **When is per-question retrieval worth it?** When your own tests show similarity picks beat one fixed set.
- **Do the labels matter?** Random labels barely hurt some tests. Keep the answers correct anyway.

## Likely follow-up questions

- Q077 Zero-shot vs few-shot prompting? https://designervenkat.online/interview/ai/zero-shot-vs-few-shot-prompting
- Q099 Why use delimiters or XML tags? https://designervenkat.online/interview/ai/why-use-delimiters-or-xml-tags
- Q100 How do you test prompts systematically? https://designervenkat.online/interview/ai/how-to-test-prompts-systematically
- Q101 What are prompt optimizers (e.g. DSPy)? (full answer coming)
- Q102 Why do prompts break when you switch models? https://designervenkat.online/interview/ai/why-do-prompts-break-when-you-switch-models

## Learn it in depth

- [Zero-shot and few-shot](https://designervenkat.online/learn/ai-engineering/zero-shot)
