Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Few-Shot Prompting — Teaching By Example | Core Prompting Techniques
Prompt Engineering for Work

bookFew-Shot Prompting — Teaching By Example

Swipe to show menu

There are tasks where telling the AI what you want isn't enough — you need to show it. This is the core principle behind few-shot prompting: instead of (or in addition to) writing instructions, you include one or more examples of the kind of output you're looking for, and let the model use those as a template.

Few-shot prompting is one of the highest-leverage techniques available to you, especially for tasks that need to match a specific voice, format, or style that's difficult to describe in words.

How Few-Shot Prompting Works

The structure is straightforward. You provide:

  1. A brief instruction (the task);
  2. One or more examples showing input → output pairs;
  3. The actual input you want the model to process.

The model reads the examples, identifies the pattern, and applies it to the new input.

Example structure:

Note
Prompt

Here is how our team writes internal status updates:

Input: The API integration is delayed due to a dependency issue on the vendor side. ETA unclear. Output: API integration delayed — vendor dependency unresolved. No ETA yet. Flagged to [Owner]. Next update: Friday.

Input: Design review completed. Three minor revisions requested by stakeholders. Changes expected by end of week. Output: Design review done — 3 revisions requested. Changes due EOW. Owner: Design team.

Now apply the same format to this update: Input: The onboarding flow testing is 80% complete. Two edge cases still being resolved by the dev team. Expected completion by Thursday.

Screenshot description: A chat window showing a few-shot prompt in full. The prompt is visually divided into three clearly labeled sections using subtle background shading. Section 1 — "Instruction": Write subject lines for re-engagement emails in the style shown below. Section 2 — "Examples": two input/output pairs. Input 1: Audience: trial users who didn't convert. Product: project management tool. Output 1: "Your projects are still waiting for you." Input 2: Audience: users inactive for 90 days. Product: design platform. Output 2: "A lot has changed since you left." Section 3 — "Your input": Audience: users who signed up but never completed onboarding. Product: HR analytics software. The AI response below produces a subject line that clearly matches the style and brevity of the two examples. An annotation points to the examples section: "The model learns the pattern from here." An annotation points to the output: "Applies the same pattern to the new input."

How Many Examples Do You Need?

The name "few-shot" reflects the fact that you typically don't need many examples to anchor the pattern:

  • One example (one-shot) is often sufficient for simple formatting or style matching;
  • Two to three examples cover most professional use cases and give the model enough variation to generalize correctly;
  • More than five is rarely necessary and can make the prompt unwieldy.

The quality of your examples matters more than the quantity. One well-chosen example that clearly demonstrates the pattern is more effective than three inconsistent ones.

Choosing The Right Examples

Your examples should be:

  • Representative — they should reflect the full range of what you're asking for, not just the easiest cases;
  • Consistent — the style, format, and level of detail should be uniform across all examples;
  • Real where possible — using examples from your actual work produces more accurate style matching than invented ones;
  • Correctly formatted — the model will replicate formatting choices, including mistakes. If your example has a structural error, expect the output to as well.

When Few-Shot Prompting Is Worth The Extra Effort

Few-shot is more work to set up than zero-shot. It pays off when:

  • You need output to match a specific existing voice or format (your company's writing style, a report template, a tone guide);
  • Zero-shot attempts have produced outputs that are consistently close but not quite right;
  • You're building a reusable prompt template that will be used repeatedly — the setup cost is a one-time investment;
  • The task involves subjective quality judgments (what makes a subject line good, what makes a summary concise) that are easier to demonstrate than explain.
question mark

Which of the following is a best practice for few-shot prompting based on the chapter content

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Section 2. Chapter 2
some-alt