Intermediate · Shaping the Output
Using examples (few-shot)
Instructions describe what you want. Examples show it. For most tasks involving classification, tone, structure, or style, examples communicate the target more precisely than any description.
This technique is called few-shot prompting. "Few-shot" means a small number of examples — typically two to five — provided before the actual task.
Why examples outperform instructions
Consider the instruction: "Write a warm but professional apology email." Every word in that instruction is ambiguous. What is warm? What is professional? How long? What tone markers indicate warmth without sacrificing professionalism?
Now consider providing an example:
Complaint: "My order arrived damaged."
Email: "We're sorry your order arrived in that condition — that is not the experience we want you to have. We have shipped a replacement and it should arrive within two business days. If there is anything else we can do, please reply to this email and we will take care of it."
The example answers every question the instruction left open: length (three sentences), tone (direct apology, no hedging, specific action), format (no subject line in the example, so the email starts immediately with the apology), and level of warmth ("that is not the experience we want you to have" is warm; "we have shipped" is professional).
The structure of a few-shot prompt
[Task instruction]
[Example input 1]
[Example output 1]
[Example input 2]
[Example output 2]
[Actual input]
[Leave this blank for Claude to fill in]
The actual input is at the bottom with no output. Claude fills in the output following the pattern established by the examples.
How many examples
Two examples establish a pattern. Five examples establish a pattern plus cover edge cases. More than five examples are rarely necessary and can make the prompt unwieldy.
Use at least one example per category in a classification task. If you are classifying sentiment as positive, neutral, or negative, include one example of each.
Choosing examples
Choose examples that represent the range of variation in your inputs, not just the easy cases. If some of your complaints are polite and some are aggressive, include both in the examples. If some of your documents are short and some are long, include both.
Examples that only cover the easy cases produce a model that handles easy cases well and fails on everything else.
If you get stuck
If Claude is following the pattern of your examples but the pattern is wrong, the examples need to be revised. The examples are the specification — if the output is wrong, the specification is wrong.
If Claude is ignoring your examples and producing something generic, the examples may be embedded in a way that makes them look like data rather than instructions. Separate them with clear labels: Example 1:, Output 1:.
Cross-reference
L10 (Precognition) and few-shot prompting combine well: provide examples that include step-by-step reasoning, and Claude will reason step by step on new inputs.
Deliverable
Pick a classification task from your work — categorizing support tickets, tagging content, classifying sentiment. Write a few-shot prompt with two to three examples. Run it on five real inputs. If the accuracy is lower than you expected, examine which cases failed and add an example that covers that failure mode.
Try these prompts
- Convert these customer complaints into apology emails. Provide 2 examples, then do the third.
- Classify the sentiment of these 3 product reviews as Positive, Neutral, or Negative.
Sign in to keep your place and tick off lessons. Reading stays open either way.