Skip to content
AI Stack Nest
BeginnerLesson 2 of 3 · 1 min read

Show, don't tell: using examples in prompts

Learn few-shot prompting: give the model one to three examples so it copies the pattern you want.

Why examples help

Sometimes it is hard to describe exactly what you want, but easy to show it. When you put a few worked examples in your prompt, the model tends to copy their pattern. This is called few-shot prompting. Using no examples is called zero-shot.

How to do it

  1. Pick one to three examples that show the input and the exact output you want.
  2. Keep the format identical in every example, including punctuation.
  3. End the prompt with a new input and leave the output blank for the model to fill in.

For instance, you can label customer reviews as Positive or Negative by showing two labelled reviews and then a third without a label. The model will usually answer with the same style of label.

Things to watch

Examples can also push the model in a direction you did not intend. If all your examples are positive, the model may lean positive. Include a mix that matches the real inputs you expect.

Examples use up space in the context window, so keep them short. And always check the answers: examples improve the pattern, but they do not make the content correct.

Try it

Run the code above to see how the examples are joined into one prompt. Then write your own examples for a task of your choice.

Try it

var examples = [
  "Review: The battery is great -> Positive",
  "Review: It broke after a week -> Negative"
];
console.log(examples.join("\n") + "\nReview: Setup was easy -> ");
Common errors
  • Using examples that disagree with each other, so the model copies the wrong pattern.
  • Giving only one kind of example when the real input will vary.

Quick check

What is few-shot prompting?

Quick check

What should your examples be like?

0 of 3 lessons done in this track