Few-shot prompting

Also called few-shot learning, in-context learning, one-shot prompting

Showing the model two or three examples of the task done well before asking it to do a new one.

Few-shot prompting means including a small number of examples in the prompt, each showing an input and the output you want. The model picks up the pattern from these examples and applies it to a new input. With one example it is called one-shot; with none, zero-shot.

Examples communicate things that are hard to describe in words: a tone of voice, an exact format, how long answers should be, or how to handle a borderline case. They are especially useful for classification with custom labels, extraction into a fixed structure, and matching a writing style.

The quality of the examples matters more than the number. Two to five good ones usually beat twenty mediocre ones. Choose examples that are varied, cover the tricky cases, and are clearly separated from the real input, for example with labels or tags. Researchers call this in-context learning, because the model adapts within the prompt without any change to its weights.

Example

To label feedback as Bug, Feature request or Praise, you add three labelled lines to the prompt: "App crashes when I upload a photo: Bug", "Please add dark mode: Feature request", "Love the new search: Praise". Then you give the new feedback and ask for its label.

Common mistake

Using examples that are all alike. If every example review is short and positive, the model may assume all reviews should be labelled positive or answered briefly. Vary length, topic and answer across your examples so the model learns the rule, not a coincidence.

Find a prompt for the task in front of you.

96 prompts in 8 categories. Copy one, fill in the blanks, paste it into any model.

Browse prompts

Promptlexity is a free library of 96 AI prompts and 8 downloadable AI skills across 8 categories, plus a glossary of 64 AI and prompting terms. Each prompt shows the exact text to paste, the variables to fill in, an example of what comes back, and why it works. Each glossary term has a plain-English definition, an example and a common mistake. 6 step-by-step guides cover the basics. No signup, works with ChatGPT, Claude, Gemini and other models.

Press Esc to close