Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

Learning path · 8 steps

Prompt and Context Engineering
  1. 1
    Temperature, Top-p and Sampling: Why the Same Prompt Gives a Different Answer
  2. 2
    Explicit Criteria vs Vague Prompts: Turn Every Adjective Into a Check a Script Can Run
  3. 3
    Few-Shot Prompting Done Right: How Many Examples, How Different, What Order, and the Leak That Lies
  4. 4
    Structured LLM Output with Pydantic: Describe the Shape Once, Check Every Reply
  5. 5
    Prompt Caching: Keep the Start of Every Request Identical and Pay for the Long Part Once
  6. 6
    Prompt Versioning and Testing in a Repo: Prompt Files, a Registry, a Hash per Answer and Tests That Gate
  7. 7
    Context Engineering: What Belongs in the Context Window, Turn by Turn
  8. 8
    Context Engineering for a Long-Running Agent: Clear, Compact, Take Notes, Prove It
  1. Blog
  2. /
  3. AI Engineering
  4. /
  5. LLM Fundamentals

Learning path: Prompt and Context Engineering · Step 3 of 8

Few-Shot Prompting Done Right: How Many Examples, How Different, What Order, and the Leak That Lies

Sort support tickets into billing, bug, feature or other by showing the model four worked examples: an easy case, a hard case, an edge case and a near miss. Then pick the count, the order and the shape, and keep the examples out of your test set.

Chaand Sheikh

·27 November 2026LLM Fundamentals

What you will learn

  • Replace a growing list of rules with a few worked examples
  • Pick a defensible example count and make each example teach something new
  • Order examples and match their shape to the real input
  • Keep the example pool and the test set apart with an overlap check

Before you start

  • What an LLM Can and Cannot Do
  • Explicit Criteria vs Vague Prompts

Instead of writing a long list of rules, you can show the model a few worked examples and let it pick up the pattern. That is few-shot prompting. The idea is simple, but four things decide whether it works: how many examples you use, how different they are, what order and shape they take, and one leak that can make your test scores lie to you.

Telling vs showing

The use case: support tickets come in, and we want to sort each one into billing, bug, feature or other.

The first idea is to tell the model the rules:

Classify the ticket as billing, bug, feature or other.
If it mentions money, it is billing, unless the money part is a
broken screen, then it is a bug, unless it asks for a new way to
pay, then it is a feature, unless the message is almost empty...

The rules keep growing, and the prompt gets harder and harder to read. The other way is to show: give the model a couple of tickets with the correct label next to each one.

Classify the ticket. Reply with the label only.

Ticket: I was charged twice this month.
Label: billing

Ticket: Export spins forever, I need my invoice.
Label: bug

A few good examples can replace a whole page of rules. The model picks up the pattern from what it sees.

A driving instructor's practice routes

How does a driving instructor get a learner ready for any road? Practise one route and the learner only knows that one street. Practise three straight roads and it is the same lesson three times; the first roundabout is a shock. Practise in town, on the highway, at a roundabout and in the rain, and the learner gets the idea of driving itself.

And here is the catch. Hand the learner the exact exam route in advance and they pass the test, then struggle on new roads. The practice routes are your few-shot examples. The exam is your test set. Make the practice different, and keep the two apart. That is this whole article in one picture.

Dial one: how many examples

Every example costs prompt space on every single call, so pick a count you can defend.

CountWhat happens
OneThe model tends to copy it too closely, even the parts that don't matter, like its length or its wording.
Three to fiveA good place to start for most tasks. Enough to show a pattern without making the prompt huge.
Ten or moreA longer prompt on every call, and the gain is often small.

The rule of thumb: start with three, and grow the count only when a test proves it helps. Since every example rides along on every call, it also adds to the token bill; LLM Tokens, Context Windows and Cost shows how that adds up.

Dial two: make them different

Each example should teach something the others don't. Here is the ticket prompt with four examples and the slot for the new ticket at the bottom:

Classify the ticket as billing, bug, feature or other.
Reply with the label only.

Ticket: I was charged twice this month.
Label: billing

Ticket: Export spins forever, I need my invoice.
Label: bug

Ticket: hi
Label: other

Ticket: Can you email me invoices every month?
Label: feature

Ticket: {ticket}
Label:
Four examples, four different lessons Easy case "I was charged twice this month." billing plainly billing Hard case "Export spins forever, I need my invoice." bug says invoice, but it is a broken button Edge case "hi" other an almost empty message Near miss "Can you email me invoices every month?" feature sounds like billing, asks for a feature
Easy, hard, edge and near miss: each example teaches the model something the other three don't.
  • Easy case. Charged twice is plainly billing.
  • Hard case. It says "invoice", so it smells like billing, but it is really a broken export button, so it is a bug.
  • Edge case. An almost empty message that just says "hi". That goes to other.
  • Near miss. It sounds like billing, but it asks for a new feature: invoices by email every month.

The swap test: if you can swap two examples and nothing new is taught, they are too alike. Replace one.

Order and shape

Two small details change results more than you would expect.

Order

Start with the simple case so it sets the basic pattern. Then the harder ones: edge cases and near misses. Put the most typical example last, because the last example tends to pull the hardest.

Don't treat this as a law, though. Order is a setting to test: shuffle the examples, run your tests again, and keep the order that wins.

Shape

Here the examples use Q: and A: with the label in capitals, but the new ticket arrives as Ticket: and Label::

Q: I was charged twice.
A: BILLING

Ticket: {ticket}
Label:

The fix is one shape everywhere:

Ticket: I was charged twice.
Label: billing

Ticket: {ticket}
Label:

Make every example look exactly like the real input: same labels, same keys, same casing.

The leakage trap

Now the big one. Few-shot examples must never come from the set you test on.

Here is how it happens. You have one file with every labelled ticket. You paste the first five into the prompt as examples, then you test on the whole file. The model has already seen some of the answers.

Leaking flow vs clean flow Leaking One ticket file every labelled ticket Examples = first five pasted into the prompt Test set = whole file model saw the answers Clean Example pool own folder, by hand + Test set never in a prompt Overlap check no example in test
Two pools and an overlap check. A leaked test is like knowing the exam route: the score looks great and means nothing.

The clean way is two pools. An example pool in its own folder, picked by hand, and a separate test set that is never shown in a prompt. Then an overlap check makes sure no example text appears in the test set. In practice: search the test set for every example text, and if any one turns up, move it out of the test set or pick a different example.

This is the same idea as the train-test split in machine learning: whatever the model learns from must stay out of what you grade it on. Train-Test Split and Data Leakage shows the same trap with a scaler.

Warning sign: test scores look too good in development, then drop with real users. Check for leakage first.

Common mistakes and the fix

MistakeWhat goes wrongFix
One exampleThe model copies its surface detailsStart with three to five
Look-alike examplesBreaks on the first unusual inputEasy, hard, edge, near miss
A different shapeThe real input looks unfamiliarSame keys, labels and casing
Examples from the test setScores you cannot trustSeparate pools plus an overlap check

Treat your examples like code: version them, test them, and change them one at a time. Prompt Versioning and Testing in a Repo shows how.

Try it yourself

  1. Pick a task and write a few-shot prompt with three look-alike examples.
  2. Replace two of them with a hard case and a near miss, and compare the results.
  3. Search your test set for every example text to check for leaks.

To sum up: show, don't only tell. Start with three to five examples that are clearly different. Put the simple case first, match the real input shape, and test the order. And keep your examples and your test set apart.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in the learning path Prompt and Context Engineering · step 3 of 8

Previous
Explicit Criteria vs Vague Prompts: Turn Every Adjective Into a Check a Script Can Run
Next post
Structured LLM Output with Pydantic: Describe the Shape Once, Check Every Reply

Related course on Udemy

Become an AI Engineer: LLMs, RAG, Agents and MCP

Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)

Related posts

The AI Stack in One Picture: Six Layers Every AI Product Is Built From

Every AI product is built from six layers: data, model, retrieval, orchestration, serving and ops, with evals and security across all of them. A restaurant analogy, one request traced through all six, and what an AI engineer actually builds around the model call.

Tokenization: What an LLM Actually Sees When You Type

A language model never sees letters, only token ids. Use tiktoken to watch strawberry become three ids, see a space or a capital change them, fix the letter-counting problem, and compare English, German and Hindi token counts.

LLM Tokens, Context Windows and Cost: What One Question Really Costs

Follow one four-word help desk question that becomes 911 input tokens. Learn what fills the context window, why chat memory grows every turn, how max_tokens cuts a reply, and how to price a call.

What an LLM Can and Cannot Do: One Prediction Loop, Its Strengths and Its Gaps

A large language model predicts the next token, over and over. That one loop makes it strong at drafting, summarising and classifying, and weak at fresh facts, exact maths, memory and guaranteed truth. See why with a three-line tiktoken script, and learn the fix for each gap.

On this page

  • Telling vs showing
  • A driving instructor's practice routes
  • Dial one: how many examples
  • Dial two: make them different
  • Order and shape
  • Order
  • Shape
  • The leakage trap
  • Common mistakes and the fix
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Become an AI Engineer: LLMs, RAG, Agents and MCP

Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.