g↗genai/ learner
Prompting and Working with AI / Lesson 04

Teaching through examples

Show a model a pattern with input-output examples to guide its reply—without changing how the model is trained.

Concept + interactive labBeginner friendly

What you will learn in this lesson.

Sometimes a style or format is much easier to show than to explain in a long list of rules. Including a few sample pairs inside your prompt helps a model follow the pattern you want.

We will cover four ideas in order:

  1. Prompt examples: worked input-output pairs placed directly inside your prompt to show a pattern.
  2. Zero-shot, one-shot, and few-shot: names for prompts with zero, one, or a small set of examples.
  3. Pattern guidance (not a guarantee): why examples steer a reply without acting as a strict rule.
  4. Context vs model weights: why examples work only while they are in the current context window (the text the model reads for a request) and never change the model’s learned settings (weights).

Running example: the bakery daily staff board

A small bakery rewrites messy staff notes into neat one-line entries in this house style: [Category] Action — short reason.

The board uses three categories: [Supplies], [Schedule], and [Equipment].

Showing a pattern can be clearer than describing it.

Imagine training a new barista to write chalkboard cards. Handing them one finished card is often faster and clearer than writing a long paragraph about tone, dashes, and word count.

In technical terms, a language model generates a reply by predicting likely next tokens from the text in its prompt. When your prompt includes sample input-output pairs (prompt examples), continuing that pattern becomes a much more likely path for the model.

Same instruction, no examples

Instruction: “Rewrite this bakery staff note as a short, calm entry for the daily staff board.”

New note: “Oven 2 runs 10 minutes slow today, so start the bread tray early.”

Illustrative reply: “Oven 2 is running about 10 minutes slow today. Please put the bread tray in earlier than usual so it finishes on time.”

Same instruction, plus examples

Same instruction, plus three sample Note → Board pairs showing [Supplies], [Schedule], and [Equipment].

New note: “Oven 2 runs 10 minutes slow today, so start the bread tray early.”

Illustrative reply: “[Equipment] Start bread tray early — Oven 2 is 10 min slow today.”

Diagram titled Prompt examples show the pattern with subtitle Sample pairs guide the reply. Left to right arrows connect a Prompt card containing Example: Note to Board line and New note: Oven 2 slow, into a Model card labelled Same weights, and out to a Reply card reading [Equipment] Start bread early. A bottom strip contrasts No examples: style is open with With examples: closer to pattern.
Prompt examples sit inside the input and guide the reply toward the pattern without changing the model’s weights.

Everyday example: two-word meeting actions

If you want meeting notes turned into tiny two-word tasks like Email Alex or Book room, showing two sample pairs in your prompt is usually clearer than explaining every word-count and verb rule.

Zero-shot, one-shot, and few-shot.

People group example-based prompts by one simple criterion: how many worked input-output examples are inside the current prompt.

Zero-shot

0 examples (instruction only)

Best for simple tasks where a clear instruction already gets a good answer and exact house style does not matter.

One-shot

1 sample pair

Sets a basic shape quickly, though one example can leave category names or edge cases open.

Few-shot

A small set (often 2–5)

Shows both the exact format and how different kinds of inputs map to different outputs.

There is no single magic number for few-shot prompts. Adding many long examples uses up space in the model’s context window, so a few short, varied examples are often better than a long pile.

Everyday example: sorting personal receipts

Suppose you want receipts labelled Food, Travel, or Home. One example shows the single-word output shape; three varied examples—one for each label—show the full set of categories you expect.

Examples guide a reply; they do not guarantee it.

Prompt examples steer which next tokens look likely; they do not lock the model into a rigid computer rule. Even with good examples, a reply can still drift, so you still check the output.

Three common ways examples fall short:

  • Inconsistent examples: if one example is a crisp [Supplies] line and another is a chatty paragraph, the model may blend both styles.
  • One-sided examples: if all three examples use the label [Supplies], the model can be nudged to repeat [Supplies] even when a note is about equipment.
  • Unfamiliar or tricky inputs: a note that mixes two topics or uses unusual wording can still break the format. When you need strict machine-readable fields such as JSON, you validate the output separately (covered in Lesson 3.5).

Everyday example: tone leaking into a refund email

If you paste three upbeat product blurbs as style examples and then ask for a calm refund reply, the model may carry the cheerful tone into a message where it does not belong.

Examples stay in the current context; they do not retrain the model.

Taping a sample card beside the bakery whiteboard helps everyone on today’s shift write matching entries, but it does not rewrite the shop’s printed handbook.

In the same way, prompt examples work inside the current context window (often called in-context learning). The model’s weights—the learned numbers produced during training—stay completely unchanged.

Inside the same conversation, many chat apps re-send earlier turns in the context window, so your examples can keep guiding later messages there. Open a brand-new chat without those examples, and the model has only your new prompt to go on.

Diagram titled Examples stay in context with subtitle Model weights do not change. Row 1 connects Chat 1: 3 examples + note to Model (same weights) to Matches board style. Row 2 connects Chat 2: note only to Model (same weights) to Style may differ. Bottom strip reads Illustrative: examples guide while in context — weights stay unchanged.
Both chats use the same unchanged model weights. The examples can guide the format while they are present in context.

Try it: add examples and watch the style shift.

Use the scripted simulation below to compare how different sets of examples steer the same bakery staff note while the model’s weights stay unchanged.

Try it in this order:

  1. Start on 0 examples and read the plain zero-shot reply.
  2. Select 1 example and notice how the [Tag] Action — reason shape appears, even though the tag name is guessed.
  3. Select 3 varied examples to see the exact [Equipment] match, then try Messy examples to see how mixed samples blur the output.
  4. Select New chat (no examples) and check both the reply and the Model weights: unchanged badge.
Scripted simulation · Bakery board

Illustrative replies only (not a live model call). The task instruction stays identical in every step so you can see what the examples change.

Current context: 0 examplesModel weights: unchanged

1. Prompt sent in this request

Zero-shot (instruction only)

Shared instruction

Rewrite this bakery staff note as a short, calm entry for the daily staff board.

No examples attached to this request.

New staff note to rewrite

“Oven 2 runs 10 minutes slow today, so start the bread tray early.”

2. Illustrative model reply

Oven 2 is running about 10 minutes slow today. Please put the bread tray in earlier than usual so it finishes on time.
What shifted: The reply is calm and useful, so zero-shot works for a simple rewrite. Without examples, the model picks its own phrasing and leaves out the shop's [Category] Action — reason house style.
Zero-shot selected. Zero examples in context. Model weights remain unchanged. Reply uses plain sentences without the bracket tag format.

Quick questions.

If I add ten examples, will the model always follow the format?

No. Extra examples can clarify tricky cases, but they still guide probabilities rather than enforce a hard rule—and long lists take up space in the context window.

Why did the model keep my format on the second message of the same chat?

Many chat apps automatically re-send earlier turns from that conversation inside the context window. The examples are still in the input, not saved inside the model’s weights.

When is zero-shot better than adding examples?

When a clear, short instruction already gives you the answer you need, zero-shot saves you typing time and keeps the prompt compact.

✎ Try it yourselfKnowledge check · Practice only

Check your understanding.

You include three [Category] Action — reason examples in a chat so a model rewrites bakery staff notes in that style, and it follows the pattern. Ten minutes later, you open a brand-new chat with the same model and send only the instruction and a new staff note, with no examples. The reply comes back as a plain two-sentence note without brackets. What best explains why?
Take this with you

Take this with you.

Showing 1–3 clear, varied input-output examples is often the fastest way to steer a model toward a specific tone or structure.

Examples guide a reply without guaranteeing it—inconsistent or one-sided samples can mislead—and they act only while they are in the current context, never changing the model’s weights.