Research Careers Contact

GlossaryFew-shot prompting

Few-shot prompting

Few-shot prompting is a technique in which a prompt includes a small number of worked examples of a task, each with an input and the desired output, before the new input the model should handle. The model infers the pattern from the examples and applies it, without any change to its weights.

How it works

A few-shot prompt has three parts: an instruction, a handful of example pairs and the new case. For a part-number extraction task, each example shows a snippet of datasheet text and the structured record extracted from it. The model reads the examples in its context window and produces output in the same form.

Research on large language models showed that they learn tasks from examples placed in the prompt, an ability called in-context learning, and that this ability grows with model size. The examples teach format, level of detail and edge-case handling more reliably than instructions alone.

The advice has shifted with reasoning models. A 2024 study found that few-shot examples lowered the accuracy of a reasoning model on hard medical questions, and its authors questioned whether in-context examples still steer models built to reason. With those models, start with clear instructions and add examples only for format.

Few-shot vs zero-shot prompting

A zero-shot prompt gives instructions only, with no examples, and the model answers from what it learned in pretraining. It is shorter and cheaper and works for common tasks with clear instructions. A 2022 paper showed that adding a simple instruction to reason step by step improves zero-shot answers on multi-step problems. Vision-language models extend zero-shot to images: given category names as text, they sort images into classes they were never trained on. Few-shot prompting costs more tokens per call but is more consistent on unusual formats, domain labels and local conventions.

Why it matters

Engineering data has its own conventions: reference designators, package names, units and the fields a record must contain. A model given only instructions guesses at those conventions. A few well-chosen examples show it what a correct record looks like, which cuts formatting errors and makes output easier to check.

How to get it right

  • Start zero-shot, with every label and field defined in plain words.
  • Add examples where errors cluster, taken from real and messy inputs.
  • Keep every example's output in exactly the required format.
  • Vary examples so the model does not copy one example's specifics.
  • With a reasoning model, test whether examples improve results before keeping them.
  • Move to fine-tuning when the task needs more examples than a prompt holds.

Few-shot prompting in robotics and drone hardware

Inspection notes, test logs and supplier documents use local conventions that general models do not know, such as defect codes, fixture names or a shop's lot format. Each new board in a high-mix build brings parts and failure modes with no labeled history, so a zero-shot pass is often the first step. A few examples from real records then teach the conventions: a BOM line where DNP marks a part left unpopulated, or a functional test entry with its fixture ID, limits and measured value. The model then fills a test record the way the team's own engineers do.

Learn more