Skip to content
FORGENO ADS GAMESUnlock all $8

Prompt Engineering & AI Automation · Unit 5 of 8

Unit 5: Few-shot examples

Zero-shot and few-shot prompts, choosing examples that cover the hard cases, the ways examples backfire, and laying them out cleanly and privately.

Opens the first lesson of this unit in Prompt Engineering & AI Automation. Every lesson is open from the start.

Lesson 1: Show, do not just tell

Goal: Explain zero-shot and few-shot prompting and what examples teach.

A zero-shot prompt describes the task and gives no examples. A few-shot prompt adds a handful of worked examples: inputs paired with the exact outputs you want. The name comes from research on large language models, which found they could pick up a new task from just a few examples placed in the prompt.

Examples are powerful because they teach things that are hard to describe: the exact format, the level of detail, the tone and, above all, judgment on borderline cases. "Label polite complaints as complaints" is an instruction; one polite complaint shown with the right label is often clearer.

Label each message as BILLING, TECHNICAL, ACCOUNT or OTHER.

Message: I was charged twice for my March invoice.
Label: BILLING

Message: The app crashes when I open the reports tab.
Label: TECHNICAL

Message: How do I add a colleague to our team plan?
Label: ACCOUNT

Message: Love the product! Quick one though: why did my bill go up this month?
Label: BILLING

Message: {the new message goes here}
Label:

The last example is the useful one. It sounds friendly and positive, yet it is a billing question, exactly the case a zero-shot prompt tends to get wrong. Start with two to five examples. More is not automatically better: every example costs tokens on every request, and a few well-chosen ones usually beat many similar ones.

Zero-shot prompt
A prompt that describes the task without any examples.
Few-shot prompt
A prompt that includes a few example inputs with the exact outputs wanted.
Shot
One worked example in a prompt.

Remember: A few good examples teach format and judgment. Include the borderline case.

Lesson 2: Choosing examples that teach

Goal: Pick examples for coverage, hard cases, variety and balance.

The examples you choose decide what the model learns from them. Good example sets share four qualities.

  • Coverage: at least one example of every category or output type you expect.
  • Hard cases: the borderline inputs that trip things up, such as the polite complaint, the email with two requests or the invoice with no date.
  • Variety: different lengths, wording and styles, so the model learns the rule rather than a surface pattern.
  • Balance: if four of five examples are BILLING, the model may lean toward BILLING when it is unsure.

Hands-on lab in the room: Few-shot example picker. Choose examples for a simulated labeler and watch its accuracy on 16 test messages change. The simulation copies the label of your most similar example: a crude stand-in, but it shows how strongly real models lean on the examples you pick.

Worked example: fixing a lopsided set

  1. A team's examples: four billing messages and one technical one. On 20 test messages, account questions are often labeled BILLING.
  2. They swap two billing examples for one ACCOUNT and one OTHER example, and add a polite complaint.
  3. Accuracy on the same 20 messages rises from 13 to 18.
  4. The two remaining errors are genuinely ambiguous messages with two requests, so they add a written rule: "If a message has two requests, label the first one."

Coverage and balance mattered more than the number of examples.

Coverage
Having at least one example of every category or case the prompt must handle.
Edge case
An unusual or borderline input that is likely to trip a prompt up.

Remember: Cover every category, include the hard cases, vary the wording, keep it balanced.

Lesson 3: When examples backfire

Goal: Recognize copied surface features, contradictions and test leakage.

Examples are strong medicine, and they have side effects. Models copy what examples have in common, including things you did not mean to teach.

PitfallWhat happensFix
Copied surfaceEvery example is two sentences, so every output is two sentencesVary the length, or state the length rule
Copied contentA name or product from an example turns up in new answersUse varied, clearly invented details, and say the examples are illustrations
ContradictionAn example breaks your written ruleFix the example: when they disagree, models often follow the example
ImbalanceOne label dominates the examplesBalance the set
Leakage into testsThe test messages are the same as the examplesKeep examples and test cases separate

Worked example: the copied sign-off

  1. All three example replies end with "Have a sunny day!"
  2. Every new reply ends that way too, including the reply to a customer whose delivery was destroyed in a storm.
  3. Fix: vary the closings in the examples, and add "Match the closing to the customer's situation."

Whatever all your examples share, the outputs will share.

The last pitfall matters most for honest testing. If your test set contains the same messages you used as examples, you are testing whether the model can copy, not whether it can handle new inputs. Keep a separate set of test cases that the prompt has never seen.

Leakage
When test cases also appear in the prompt's examples, so test results look better than real performance.

Remember: Whatever the examples share, the outputs copy. Never test on your own examples.

Lesson 4: Formatting examples well

Goal: Lay out examples clearly and remove personal data from real ones.

How you lay out examples matters as much as which ones you pick. A few habits keep them clear.

  • Mark each example the same way, with "Input:" and "Output:" labels or <example> tags, so the model can see where each starts and ends.
  • Make example outputs look exactly like the output you want, including the JSON fields and their order.
  • Put the examples after the instructions and before the new input.
  • Say what they are for: "Here are examples of the style and format; the details are invented."
<example>
<input>Hi, the blue mugs in order 5512 arrived chipped (3 of 6).</input>
<output>{"category": "damaged_item", "order_id": "5512", "quantity_affected": 3}</output>
</example>
<example>
<input>Do you deliver to the islands?</input>
<output>{"category": "question", "order_id": null, "quantity_affected": null}</output>
</example>

Real past inputs make the best examples, because they look like what the prompt will actually face. But remove personal information first: names, email addresses, phone numbers, street addresses and account numbers. Replace them with invented ones. Example text is sent with every single request and may be kept in logs.

Synthetic example
An example written or altered so it contains no real personal data, while still looking like a real input.

Remember: Same labels or tags for every example, exact output format, examples before the new input, no real personal data.

Practise it in Prompt Engineering & AI Automation

Each lesson ends with three questions that check you can use the idea, not just recognise it. Wrong answers explain why and come back in Review. The unit ends with a 6-question quiz; pass it with 80% or more to master the unit. Hands-on lab: Few-shot example picker.

Every lesson is free: no ads, no lives and no paywall.