Generative AI

Few-Shot Prompting

Few-shot prompting is the technique of including a small number of worked examples of input and desired output in a prompt so that the model copies their format and judgment on new inputs.

What is few-shot prompting?

Few-shot prompting is the technique of placing a handful of examples, usually two to five, inside the prompt to show the model what a correct answer looks like. Each example pairs an input with the desired output. The model then treats a new input the same way, matching the format, level of detail, and decision rules the examples demonstrate. Zero-shot prompting gives instructions with no examples at all.

Few-shot prompting borrows its name from few-shot learning, but no training takes place. The examples are read fresh on every request and influence only that response. The technique works because large language models are strong at pattern continuation: once they see three inputs mapped to three outputs, the fourth mapping follows.

Few-shot prompting in practice

A city’s service request line receives free-text reports that must be routed to one of forty departments. Written category definitions produced inconsistent routing, because residents describe a broken streetlight, an overgrown lot, or a missed trash pickup in many ways. Adding five examples per ambiguous category, chosen from past misrouted requests, settled the hard cases. The examples showed the model, for instance, that “water pooling on the sidewalk” belongs to stormwater rather than to the water utility.

What to watch for

  • Examples consume tokens on every request, so pick the few that resolve real ambiguity rather than many that repeat the obvious.
  • The model imitates everything in the examples, including mistakes and inconsistent formatting, so review them carefully.
  • The order of examples can bias the output, so test with the order shuffled.

← Back to AI Glossary