Why it matters

Many tasks that fail zero-shot succeed with 3-5 well-chosen examples. Few-shot is cheap (no training) and reversible (change prompt any time). Understanding it well is core prompt engineering.

Advertisement

The architecture

Structure: instruction + examples (input → output pairs) + new input. Model sees the pattern and applies it.

Number of examples: 3-5 typical. Diminishing returns beyond ~10. Very long few-shot uses tokens without proportional gain.

Few-shot prompt layoutInstructiontask descriptionExamplesinput → output pairsNew inputapply patternExample diversity matters more than count; representative examples generalize better
Few-shot structure.
Advertisement

How it works end to end

Example selection: pick examples that cover the task's range. Include tricky cases you want the model to handle. Diversity of examples > raw count.

Format consistency: examples must use the exact format you want in output. Model imitates the pattern precisely.

Dynamic few-shot: for classification, retrieve most similar training examples per query. Higher quality than fixed examples.