
You've written a prompt. The AI responds with something technically correct but completely wrong for your needs — the format is off, the tone is too casual, or it interpreted your request in a way you never intended. So you rewrite the prompt, get something slightly better, and iterate for another ten minutes. Sound familiar?
The frustrating part isn't that the AI is bad at its job. It's that you're giving it incomplete instructions. A large language model has seen an enormous range of text during training, which means when you ask it to "summarize this report," there are hundreds of valid interpretations of what a "summary" should look like. Without examples, you're asking the model to read your mind. Few-shot prompting is the systematic practice of embedding examples directly into your prompt to dramatically narrow that interpretive gap — and done right, it can turn a frustrating back-and-forth into a reliable, repeatable process.
By the end of this lesson, you'll be able to design prompts that produce consistently high-quality output without endless iteration. You'll understand the mechanics of why examples work, when they're worth the added complexity, and how to construct them strategically for real analytical and operational tasks.
What you'll learn:
This lesson assumes you're comfortable writing basic prompts and have a working understanding of how large language models process text. You should know what temperature and system prompts are, even if you don't use them every day. If you're completely new to prompting, work through the earlier lessons in this learning path first.
Here's a concrete example. Say you're building an automated system to triage customer support tickets for a SaaS company. Each ticket should be labeled as billing, technical, account, or other. You write this prompt:
Classify the following customer support ticket into one of these categories:
billing, technical, account, other.
Ticket: "I've been charged twice this month and I can't log in to fix it."
The model might return billing. Or it might return billing, account. Or it might return a paragraph explaining that the ticket contains both billing and access issues and then ask you for clarification. All three responses are defensible, but only one is useful to your pipeline.
The problem is that your instruction is underspecified. You haven't told the model:
You could add more instructions to handle each of these edge cases, and eventually you'd get something that works. But this approach has a ceiling. Natural language instructions are inherently ambiguous — explaining every edge case in prose creates new ambiguity as fast as you resolve the old kind.
Examples are fundamentally different. When you show the model an input paired with the exact output you want, you communicate format, priority rules, edge case handling, and tone all at once. You're not telling the model what to do — you're demonstrating it.
Zero-shot prompting means giving the model a task with no examples at all. Just instructions, an optional system prompt, and the input. This is what most people start with, and for a surprisingly large number of tasks, it works well.
Zero-shot is appropriate when:
The task is well-defined and common in training data. Models have seen millions of examples of summarization, sentiment analysis, translation, and basic classification during training. For these tasks, zero-shot often works because the model's training has already built up strong priors about what a good output looks like.
The output format is standard. If you're asking for JSON where the keys are intuitive, or a bulleted list, or a simple yes/no answer, the model's default behavior will usually get you there.
You're exploring or prototyping. Before spending time constructing examples, always try zero-shot first. You'll learn a lot about where the model's default behavior fails, which tells you exactly what your examples need to correct.
Here's a zero-shot prompt that works well:
You are a data analyst. Summarize the following quarterly sales report
in three bullet points, each under 20 words. Focus on trends, not raw numbers.
Report: [report text here]
This works because summarization is a common task, the format constraint ("three bullets, under 20 words") is unambiguous, and the focus instruction ("trends, not raw numbers") rules out the most common failure mode. You've eliminated enough degrees of freedom that the model's defaults cover the rest.
Zero-shot fails when the task is specialized, when your definition of "correct" is idiosyncratic, or when you need the output format to match a downstream system precisely. That's where few-shot comes in.
Few-shot prompting works by prepending one or more input-output pairs to your actual query. The model uses these pairs to infer patterns and apply them to the new input.
Here's the structure:
[Task description]
Input: [example input 1]
Output: [example output 1]
Input: [example input 2]
Output: [example output 2]
Input: [example input 3]
Output: [example output 3]
Input: [your actual query]
Output:
That trailing Output: with nothing after it is a deliberate prompt — you're signaling to the model that it should produce an output following the same pattern.
Let's go back to the ticket classification problem and add examples:
Classify the following customer support ticket into exactly one category.
Choose the category that represents the PRIMARY issue.
Categories: billing, technical, account, other
Input: "I was charged $99 last week but I cancelled my subscription two months ago."
Output: billing
Input: "The export to CSV button doesn't work — I get a blank file every time."
Output: technical
Input: "I need to add two new team members but I've forgotten my admin password."
Output: account
Input: "Do you have an affiliate program?"
Output: other
Input: "I've been charged twice this month and I can't log in to fix it."
Output:
Notice what the examples communicate without you ever stating it explicitly:
The model has learned your output format, your priority rule, and your category definitions all from four examples.
Tip: Always end your few-shot block with the actual query followed by
Output:(or whatever label you're using). Without this final prompt token, some models will continue generating more examples rather than answering your actual question.
Choosing examples at random is one of the most common mistakes practitioners make. A well-designed few-shot set is a small dataset — it should be designed, not grabbed.
Your examples should collectively demonstrate every output category, format variation, or structural element the model might need to produce. If you're building a classifier with four categories, having three examples of technical and one of billing is going to skew your results heavily toward technical. Aim for rough balance across your output space.
The inputs in your examples should look different from each other. If all your example tickets are about subscription billing, the model will over-index on billing-related language even for unrelated queries. Inputs should vary in length, vocabulary, tone, and structure.
Your examples should skew toward the cases where the model gets confused, not the cases where it would get it right anyway. Easy cases provide little signal. Think about:
For the support ticket classifier, a powerful example might be:
Input: "I keep getting invoices for a plan I downgraded three months ago.
I've tried updating this in my account settings but the option is greyed out."
Output: billing
This example explicitly teaches the model that when billing and account access are both present, the billing dimension is primary in your system.
Every example output should look exactly like what you want the real output to look like. If you want JSON, your examples should be valid JSON. If you want a two-sentence summary, your examples should be two sentences. If you want the model to respond in a specific tone, write your examples in that tone.
Warning: Format inconsistency across examples is a major source of output drift. If one example uses
Output: billingand another usesOutput: Billing Issue, the model has no way to know which format you actually want. Pick a format and apply it identically across all examples.
Rather than approaching example selection intuitively, use this process:
Step 1: Define the output schema first. Before you write a single example, decide exactly what a correct output looks like. Write it down as a precise template. For classification: one lowercase label. For extraction: a JSON object with specified keys. For transformation: a specific string format. This schema is what you're training toward.
Step 2: Enumerate failure modes. Write down every way the model could produce an output that's technically plausible but wrong for your use case. Each failure mode is a candidate for an example to address.
Step 3: Sample inputs that trigger each failure mode. Find or construct inputs where the wrong behavior would naturally occur. These are your example inputs.
Step 4: Write the correct output for each. This forces you to make explicit decisions about priority rules and edge cases. If you find yourself unsure what the correct output should be, that's a signal your task definition needs clarification before you write more prompts.
Step 5: Test with your actual distribution of inputs. Run your few-shot prompt against 20–30 representative real inputs and look for systematic failures. These failures point to gaps in your example set.
Let's work through several realistic scenarios with complete prompts you can adapt.
You're processing press releases to extract company names, deal values, and deal types into a structured format for a financial database.
Extract the key deal information from the following press release excerpt.
Return a JSON object with keys: company_name, deal_value_usd, deal_type.
Use null for any field not mentioned.
deal_type must be one of: acquisition, merger, investment, partnership, ipo, other
---
Text: "Vertex Analytics announced today that it has completed its acquisition
of DataSpark Inc. for $47 million in an all-cash transaction."
Output: {"company_name": "Vertex Analytics", "deal_value_usd": 47000000, "deal_type": "acquisition"}
---
Text: "BlueSky Ventures led a $12.5M Series B round for logistics platform
ShipWave, with participation from existing investor Meridian Capital."
Output: {"company_name": "ShipWave", "deal_value_usd": 12500000, "deal_type": "investment"}
---
Text: "Northgate Financial and Summit Bank have signed a definitive agreement
to combine operations in a deal valued at approximately $2.1 billion."
Output: {"company_name": "Northgate Financial", "deal_value_usd": 2100000000, "deal_type": "merger"}
---
Text: "Algorand Health announced a strategic collaboration with
MedCore Systems to integrate predictive analytics into clinical workflows."
Output: {"company_name": "Algorand Health", "deal_value_usd": null, "deal_type": "partnership"}
---
Text: [your actual text here]
Output:
Notice what the examples are doing here:
2.1BYou're building a workflow to rewrite technical error messages from your platform into user-friendly notifications.
Rewrite the following technical error message as a friendly, non-technical
notification for end users. Keep it under 30 words. Don't use the word "error."
Maintain a calm, helpful tone.
Technical: "NullPointerException in DataLoader.fetchRecords() at line 247:
expected non-null RecordSet but received null"
Friendly: "We couldn't load your records right now. Please refresh the page —
if this keeps happening, contact support and we'll sort it out."
Technical: "HTTP 503: Service Unavailable — upstream dependency timeout
after 30000ms in report generation service"
Friendly: "Your report is taking longer than usual to generate.
Give it a minute and try again — we're on it."
Technical: "PermissionDeniedError: User ID 8841 lacks WRITE access to
resource /workspaces/finance-q3/datasets/raw"
Friendly: "It looks like you don't have permission to edit this dataset.
Check with your workspace admin to get access."
Technical: [your error message here]
Friendly:
These examples collectively teach: avoid technical jargon, replace "error" language with process-oriented language, and include a concrete next step for the user. You can't communicate that cleanly with instructions alone.
You're building a pipeline that processes customer interview transcripts and produces structured summaries for a CRM.
Summarize the following customer interview transcript into a structured note
for our CRM. Use this exact format:
Pain Points: [one sentence]
Current Solution: [one sentence or "None mentioned"]
Key Priorities: [2-3 bullet points, each under 10 words]
Sentiment: [Positive / Neutral / Negative / Mixed]
---
Transcript: "We've been using spreadsheets forever, honestly it's a nightmare.
Three people updating the same file, version control is nonexistent.
We tried one tool last year but it was too complex for our team.
Really what we need is something dead simple — our team is not technical."
Summary:
Pain Points: Manual spreadsheet coordination causing version conflicts across team.
Current Solution: Attempted one software tool but abandoned due to complexity.
Key Priorities:
- Simple, non-technical interface
- Multi-user editing and version control
- Ease of onboarding for non-technical staff
Sentiment: Negative
---
Transcript: "Honestly, things are going pretty well. We use [Competitor] and it
does most of what we need. The reporting is a bit weak but we work around it.
If you could match their core features at a better price point, I'd consider switching."
Summary:
Pain Points: Reporting capabilities are limited in current solution.
Current Solution: Using [Competitor] for core workflow management.
Key Priorities:
- Competitive pricing
- Feature parity with current tool
- Stronger reporting functionality
Sentiment: Neutral
---
Transcript: [transcript here]
Summary:
More examples are not always better. There are real tradeoffs.
Pros of more examples:
Cons of more examples:
As a practical rule:
Tip: If you find yourself needing more than 8–10 examples to get reliable behavior, consider whether you should be fine-tuning the model rather than prompt engineering. Few-shot prompting has a practical ceiling; fine-tuning on a labeled dataset is the next tier.
Research on LLMs has consistently found that models are sensitive to the order in which few-shot examples appear. The most recent examples (closest to your actual query) tend to have the strongest influence on the output.
This creates two useful techniques:
Put your most important edge case example last. If there's a failure mode you really care about — say, the model keeps miscategorizing multi-issue tickets — put the example that corrects that behavior immediately before your actual query.
Don't put all examples of one class together. If you cluster all your technical examples, then all your billing examples, the model may over-attend to the pattern of the most recent cluster. Interleave examples across categories.
Warning: Don't use recency effects as a substitute for good example design. Relying on example order to paper over a poorly constructed example set will make your prompts fragile and hard to maintain.
Symptom: The model starts incorporating vocabulary or phrasing from your examples into its outputs, even when it's not appropriate.
Example: You use the phrase "Please refresh the page" in one of your friendly error message examples, and now the model adds "Please refresh the page" to almost every rewrite, even when it makes no sense.
Fix: Review your examples for idiosyncratic phrasing that shouldn't generalize. Make your examples diverse in surface-level language while being consistent in underlying structure.
Symptom: The model follows your format for simple inputs but drifts to a different format for complex inputs.
Example: Your classifier returns the label correctly for short tickets but starts returning the label followed by an explanation ("billing — because the user mentioned being charged twice") for longer tickets.
Fix: Add an example that pairs a complex, long input with the minimal correct output. Make it explicit in your instruction that explanation is not requested.
Symptom: The model over-predicts one category.
Example: You have four examples of technical issues and one each of billing, account, and other. The model classifies almost everything as technical.
Fix: Balance your examples across output classes. If some classes are genuinely rare, be deliberate about including at least one example of each — even if you have to construct a slightly artificial input.
Symptom: Output from a previous API call influences the current one.
This only applies if you're maintaining conversation history in a multi-turn context. If you're making independent API calls with your few-shot prompt, this isn't an issue. But if you're using a chat interface or passing conversation history, previous responses can contaminate the model's behavior.
Fix: For production pipelines, make independent API calls rather than building on conversation history. Pass your full few-shot prompt fresh with each call.
Symptom: Despite providing clear examples, the model reverts to a different format or interpretation.
Common causes:
Fix: Check instruction-example consistency first. Then check example diversity. If neither helps, test whether zero-shot with a very explicit instruction outperforms your few-shot approach — sometimes it does.
Build a few-shot prompt for the following scenario, then test it systematically.
Scenario: You work in operations for a B2B software company. Your team receives contract amendment requests by email. Each request must be routed to one of three internal teams: legal (scope changes, liability, IP), finance (payment terms, pricing, discounts), or sales (relationship issues, account expansion, renewal negotiations). Some requests span multiple categories — route to the team that handles the primary issue.
Step 1: Write out your output schema. What does a correct response look like, exactly?
Step 2: Identify at least three failure modes — cases where a naive classifier would get this wrong.
Step 3: Write four examples that collectively address your failure modes. At least one should be an edge case that spans multiple categories.
Step 4: Test your prompt against these 5 inputs and evaluate accuracy:
1. "We need to extend the payment schedule from net-30 to net-60 given
our current cash position."
2. "The original statement of work didn't include API access —
we need to add that to the agreement."
3. "Our procurement team has raised concerns about the indemnification
clause in section 4.2."
4. "We're planning to expand from 50 to 200 seats next quarter and
want to lock in current pricing."
5. "The late payment penalty clause conflicts with our standard vendor
terms — our legal team won't approve it as written."
Step 5: For any input the model gets wrong, diagnose why using the failure mode framework from the previous section and revise your example set.
Few-shot prompting is one of the highest-leverage skills in practical AI work. The core insight is that examples don't just clarify your intent — they communicate format, priority rules, edge case handling, and tone in a way that natural language instructions rarely can.
The key principles to carry forward:
Where to go next:
The best prompt engineers aren't the ones who write the cleverest instructions. They're the ones who think most carefully about what they're actually asking the model to do, and communicate it with examples precise enough to leave nothing ambiguous.
Learning Path: Intro to AI & Prompt Engineering