# Few-shot prompting

> Show the model two or three worked examples instead of describing the format in words.

Concept · Models & prompting · https://levelcode.org/concepts/few-shot-prompting

**Few-shot prompting** means putting a few input→output examples in the prompt before the real input. Models are very good at continuing a pattern. An example shows tone, format, length and edge-case handling more precisely than a paragraph of instructions.

```text
Classify each support message as billing, bug, feature_request or other.
Answer with the label only.

<example>
Message: I was charged twice this month.
Label: billing
</example>
<example>
Message: The export button does nothing on Safari.
Label: bug
</example>
<example>
Message: Could you add dark mode?
Label: feature_request
</example>

Message: {{message}}
Label:
```

With chat APIs you can also give examples as earlier user/assistant turns. Tagged blocks inside one prompt, like `<example>` above, work just as well and are easier to manage.

## Choosing examples

- **Cover the variety:** different lengths, phrasing, and the tricky cases. That might be a message that looks like billing but is a bug, or the "none of these" case.
- **Vary the answers.** If every example is labelled `bug`, the model will lean towards `bug`.
- **Make them exactly right.** The model copies mistakes, formatting quirks and length as faithfully as anything else.
- **Three to five is usually enough.** Beyond that, adding examples helps less, while cost and the chance of over-fitting to their surface features go up.
- **Pick them dynamically** for wide-ranging inputs: embed your example bank and include the examples most similar to the current input ([embeddings](https://levelcode.org/concepts/embedding-similarity)).

## When to use it

- **Format and style are hard to describe** but easy to show: a particular summary voice, a labeling convention, a SQL dialect.
- **Classification and extraction** with fuzzy boundaries between categories.
- **Not when the output must match a strict schema.** Use [structured outputs](https://levelcode.org/concepts/structured-outputs) for that, perhaps with one example to show how optional fields are filled.

Keep the examples near the instructions and above the variable input, so they're part of a stable prefix that [prompt caching](https://levelcode.org/concepts/prompt-caching) can reuse. Check that they help by running [evals](https://levelcode.org/concepts/llm-as-judge) with and without them.
