LearnAI ToolsCareerPractice BuildsPlayDevelopmentContact
Lesson 412 min read

Few-Shot Prompting: Teaching by Example

Learn zero-shot, one-shot and few-shot prompting: how a handful of good examples shows an AI exactly what you want, and how bad examples quietly mislead it.

On this page 7 sections

Introduction

Some things are hard to describe but easy to show. Try explaining in words exactly how you want product descriptions to sound — the length, the rhythm, which details come first. Now imagine simply showing three descriptions you like. The examples carry all of that information at once. In prompting, this is called few-shot prompting, and it is one of the most reliable techniques you can learn.

What You Will Learn
  • The difference between zero-shot, one-shot and few-shot prompts.
  • Why examples steer a model so strongly.
  • How to choose and format examples, and the traps to avoid.

Zero-Shot, One-Shot and Few-Shot

A “shot” is an example of the task, with its input and the answer you want. A zero-shot prompt gives only instructions. A one-shot prompt adds a single example, and a few-shot prompt adds several — typically two to five.

Few-shot prompt
Classify each customer review as Positive, Negative or Mixed.
Review: "Arrived quickly and works perfectly."
Label: Positive
Review: "Great screen, but the battery dies by lunchtime."
Label: Mixed
Review: "Stopped working after two days. Waste of money."
Label: Negative
Review: "Comfortable to wear, though the strap feels cheap."
Label:

The examples teach the model three things at once: the exact labels to use, that “Mixed” exists for reviews with both good and bad points, and that the answer is a single word with no explanation. Writing all of that as instructions would take longer and still leave room for misunderstanding.

Mini Challenge · Predict the Output

Given the few-shot prompt above, what is the model most likely to write after the final “Label:”?

Choose one answer

Why Examples Work

Recall from Lesson 1 that a model predicts the most fitting continuation of its context. When the context contains a repeated pattern — input, label, input, label — the most fitting continuation is another item that follows the same pattern. Examples therefore control the format very strongly, and they also communicate subtler things such as tone, level of detail and how to handle borderline cases.

Examples work best together with instructions, not instead of them. The instruction says what the task is and why; the examples show what a good answer looks like.

When should you reach for examples? A good rule is to start zero-shot with clear instructions, and add examples when the answers are inconsistent, when the format must match exactly, or when the task depends on a judgement that is hard to put into words — such as your brand’s tone of voice or where you draw the line between two categories. If plain instructions already give you what you need, examples only add length and cost.

Choosing Good Examples

  • Cover the variety you expect: include easy and tricky cases, and every label or category you want the model to use.
  • Make them consistent: same structure, same labels, same style. The model copies inconsistency too.
  • Keep them realistic: examples close to your real inputs teach more than artificial ones.
  • Separate them clearly: use the same markers (“Review:”, “Label:”) or tags, so the model can tell where each example starts and ends.
  • Use a few, not dozens: three to five good examples usually beat twenty mediocre ones, and they cost fewer tokens.

Common Traps

Because models copy patterns so faithfully, examples can teach the wrong lesson. If every example answer is about 20 words long, the model will write about 20 words even when a case needs more. If four of your five examples are labelled “Positive”, the model may lean towards “Positive” for unclear inputs. If all examples are about one topic, answers can drift towards that topic’s vocabulary.

Another trap is copying content: when examples contain specific facts or names, the model may reuse them in answers where they do not belong. Use neutral, representative examples, and when you only want to show a format, say so: “Follow the format of these examples; the content will be different.”

Mini Challenge · Spot What's Missing

This prompt will be used to sort hundreds of support emails into Billing, Technical or Other. What is the biggest problem with its examples?

Prompt
Sort each email into Billing, Technical or Other.

Email: "I was charged twice this month."
Category: Billing

Email: "Can I get a refund for last month?"
Category: Billing

Email: "My invoice shows the wrong address."
Category: Billing

Email: "The app crashes when I log in."
Category:
Choose one answer

Key Takeaways

  • Few-shot prompting shows the model examples of input and desired output.
  • Examples strongly control format, labels, tone and length.
  • Choose varied, consistent, realistic examples that cover every category.
  • Watch for traps: models copy length, imbalance and even specific content from examples.

Summary

Examples are the fastest way to show exactly what you want. In the next lesson you will use them, together with clear specifications, to get output in strict formats such as JSON, tables and XML-tagged sections.

Next Lesson →

Structured Output: Getting JSON, Tables & XML from AI