← All news

News / Learn / Prompt engineering

What is few-shot prompting?

You'll be able to steer a model's output format and behavior by including worked examples in your prompt.

Few-shot prompting means putting a few examples of the task right into your prompt. You show the model a few inputs paired with the answers you want, then give it a new input. The model picks up the pattern from the examples and follows it.

Many product features depend on consistent output, like a fixed label, a short summary style, or a specific data shape. Examples are often the fastest way to get that behavior without training anything. They are cheap to change, so you can iterate on them while you learn what your users need.

A few-shot prompt has three parts: an instruction, a set of example input and output pairs, and the new input you want answered. The model reads the whole prompt as one block of text. It predicts what comes next, and the examples show it what a good continuation looks like.

The examples work by demonstration, not by explanation. Showing three cases of a sentiment label teaches the model the label set, the casing, and the format more reliably than a long paragraph describing them. Use examples that cover the range of inputs you expect, including a few edge cases.

The number of examples is a trade-off. More examples use more of the context window, which costs tokens and adds latency. Past a point, extra examples add little. Start with a small number, such as two to five, and add more only when the output still drifts.

Example order and balance matter too. If every example has the same answer, the model may copy that answer. Mix the outputs across the labels or shapes you need, and keep the formatting identical across all examples so the pattern is clear.

A prompt that classifies support tickets by urgency, with three examples and one new ticket to label.

Classify each support ticket as LOW, MEDIUM, or HIGH urgency.

Ticket: I can't log in and my payroll runs today.
Urgency: HIGH

Ticket: Could you change the color of the export button?
Urgency: LOW

Ticket: Invoices show the wrong tax rate for one customer.
Urgency: MEDIUM

Ticket: The app crashes when I open settings.
Urgency:

A short sketch to show the idea. Check the official docs of the tool you use.

  • Examples that all share one answer Mix the outputs across every label or format you expect. Otherwise the model may favor the repeated answer.
  • Inconsistent formatting between examples Keep the same layout, spacing, and labels in every example. Small differences teach the model unwanted variation.
  • Assuming more examples always helps Test with a few examples first. Adding many more costs tokens and latency and may not improve results.
  • Examples that don't match real inputs Draw examples from real or realistic data, including messy cases. Clean, toy examples can hide failures.

Study chain of thought prompting, which shows the model intermediate reasoning steps in the examples. Then learn how to build a small eval set so you can measure whether your examples actually improve results.

Is few-shot prompting the same as fine-tuning?

No. Few-shot prompting puts examples in the prompt for a single request. Fine-tuning changes the model's weights using a training dataset. Few-shot is faster to try and easier to change.

What is the difference between zero-shot and few-shot?

Zero-shot gives the model only an instruction, with no examples. Few-shot adds a small number of example input and output pairs before the new input.

How many examples should I use?

Start with a few, often two to five, and test. Add more only if the output is still inconsistent. The right number depends on the task and your context budget.

Do examples have to be perfect?

They should be correct, because the model copies what it sees. They do not need to be polished, but wrong answers in examples will teach wrong behavior.

Can few-shot examples prevent hallucination?

Not on their own. Examples shape format and style well, but they do not guarantee facts are correct. Grounding the model in source material is a separate technique.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.