Few-Shot Prompting

Few-shot prompting means providing two or more examples before the task.

One example shows the model one data point. Two or three examples let it identify the actual pattern, not just copy the coincidental features of a single sample.

When one example isn't enough

Imagine you're teaching someone to classify customer reviews as Positive, Negative, or Neutral. If you show one example — a long, enthusiastic review labeled Positive — maybe you chose something long and enthusiastic, not something positive. Two or three examples, chosen to cover different parts of the range, make the actual rule clear.

The model learns the rule from the examples rather than from written instructions.

The input → output format

The cleanest few-shot structure uses consistent delimiters:

Text: "Great service!" → Positive
Text: "Waited 45 minutes." → Negative
Text: "It was fine, nothing special." → Neutral
Text: "The camera is crisp but the battery is terrible." → ?

This explicit format makes it easy for the model to parse the pattern and apply it to the new input.

A live example: sentiment classification

Zero-shot version:

Classify this review as Positive, Negative, or Neutral:
"The camera is crisp but the battery is terrible."

Few-shot version:

Classify each review as Positive, Negative, or Neutral.

Review: "Shipping was fast and the product looks exactly like the photos." → Positive
Review: "Broke after one week. Complete waste of money." → Negative
Review: "It works as described. Nothing impressive, nothing wrong." → Neutral

Review: "The camera is crisp but the battery is terrible." → ?

The few-shot version is more reliable because the examples define what Positive, Negative, and Neutral mean in this specific context — more precisely than a written definition could.

How many examples is enough

Two to four well-chosen examples is usually the right range. More examples add precision but at a cost: they use tokens and make the prompt longer. Beyond four, each additional example usually adds very little.

Make sure your examples cover the range you expect. If you're classifying reviews, don't give three positive examples and then ask about a negative.

Using it for consistent HTML

Few-shot also works well for generating HTML components in a consistent style. Paste two or three existing components from your page as examples, then ask for a new one:

Here are examples of how my page components are structured:

Example 1:
[paste first HTML block]

Example 2:
[paste second HTML block]

Write a third card in the same style for: [description of new content].

Compare the result to the one-shot version. The extra example usually produces a tighter style match, especially for class names, tag choices, and spacing patterns that appear in multiple places on your page.

One thing to keep in mind

Few-shot is a runtime technique. It works within a single conversation and doesn't permanently change the model. If you start a new conversation, you start from zero again.