---
title: Few-Shot Example Selection — Prompt Engineering Technique
description: Which examples you include in a few-shot prompt — and their order — strongly affects results. Choosing relevant, representative, well-balanced examples (often ones similar to the input) outperforms picking them at random.
canonical: https://prompeteer.ai/techniques/few-shot-example-selection
category: Foundational patterns
---

# Few-Shot Example Selection

Which examples you include in a few-shot prompt — and their order — strongly affects results. Choosing relevant, representative, well-balanced examples (often ones similar to the input) outperforms picking them at random.

## What it is

Few-shot example selection is the practice of deliberately choosing the demonstrations placed in a prompt rather than grabbing arbitrary ones. Research shows in-context learning is sensitive to which examples are used, how they are ordered, and even their label distribution — poor choices can hurt performance while good ones lift it substantially.

A widely used strategy is to retrieve examples semantically similar to the current input (dynamic, input-specific selection), and to balance label coverage and ordering so the model is not biased toward a majority class or a position effect. It turns few-shot prompting from a static block into a tuned, sometimes retrieval-driven, component.

## When to use

- Few-shot results are unstable or sensitive to which examples you happen to pick.
- You have a pool of examples and can select the most relevant per input.
- Label balance or ordering effects are skewing predictions.
- You can afford a retrieval step to pick input-similar demonstrations dynamically.

## How it works

1. Curate a diverse, correct pool of candidate examples.
2. For each input, select the most relevant examples (e.g. by semantic similarity).
3. Balance label coverage and vary or fix ordering deliberately to limit bias.
4. Evaluate selection choices empirically rather than assuming they help.

## Illustrative structure

The structure adds a selection step before assembling the few-shot prompt: for a new input, retrieve the K most similar solved examples from a pool, order them consistently, then build the standard few-shot block from those K rather than from fixed or random examples.

## Pitfalls

- Retrieved examples too similar to each other reduce useful coverage.
- Ordering and majority-label bias can dominate; test different orders.
- Dynamic selection adds a retrieval dependency and latency.
- Leaking near-duplicates of the test input as examples inflates apparent quality.

## Sources

- [Liu et al. (2021), What Makes Good In-Context Examples for GPT-3?](https://arxiv.org/abs/2101.06804)
- [Zhao et al. (2021), Calibrate Before Use: Improving Few-Shot Performance](https://arxiv.org/abs/2102.09690)

## Related techniques

- [few-shot-prompting](https://prompeteer.ai/techniques/few-shot-prompting)
- [retrieval-augmented-generation](https://prompeteer.ai/techniques/retrieval-augmented-generation)
- [context-engineering](https://prompeteer.ai/techniques/context-engineering)
