Few-Shot Prompting: Teach by Example

Prompt Engineering · Intermediate · Lesson 3

Show the model 2-5 examples to teach it new tasks, formats, and styles with high consistency.

Few-shot prompting teaches the model by showing it two to five examples before asking it to do the real work. Each example pairs an input with the exact output you want, so the model learns the pattern, tone, and format from the examples themselves.

Why this matters

Why it matters: few-shot is the most reliable way to get consistent, on-brand output. When the model sees three finished examples, it does not have to guess what "good" looks like - it imitates it.

Core concepts

The structure of a few-shot prompt is simple: a brief instruction, two to five example pairs, and then the real input. The examples carry most of the weight, so the instruction can be short.

Step-by-step walkthrough

Here is a real example for tone matching. Instruction: "Rewrite each customer message in a calm, professional support tone." Then three pairs: a blunt message and its professional rewrite, a panicked message and its calm rewrite, and a terse message and its warm rewrite. Finally, the real customer message.

Real-world examples

The examples you choose matter more than how many you use. Good examples show contrast, covering the range of cases the model will see. A few-shot prompt for JSON extraction should include an easy case, a nested case, and an edge case like a missing field.

Three to five examples is the sweet spot. Fewer than two and the model has too little to learn from; more than five usually adds nothing and wastes tokens. Quality beats quantity.

Advanced tips

Few-shot excels at tasks with a distinct style or format: rewriting in a voice, converting to JSON, grading answers against a rubric, or following a brand guideline. It is the tool for "I want more outputs that look exactly like this."

The main cost is effort. You must craft the examples by hand, and they must be genuinely good, because the model will imitate their weaknesses too. A typo in an example becomes a pattern in the output.

Practice exercises

Practice by taking a repeated format you produce at work - a status report, a code review, a product description - and build a few-shot prompt with three hand-written examples. You will see consistency jump immediately.

Common mistakes to avoid

Common mistakes: using inconsistent examples, showing only perfect cases when real inputs are messy, and skipping the instruction so the model does not know the examples are examples. Keep examples consistent, representative, and clearly separated.

Summary and next steps

Build a reusable few-shot prompt for your most repeated output formats and keep the examples consistent, representative, and clearly separated.

Key Takeaways