Few-Shot Prompting: How to Choose Examples That Improve LLM Accuracy
few-shot promptingin-context learningprompt examplesLLM accuracyprompt testing

Few-Shot Prompting: How to Choose Examples That Improve LLM Accuracy

PPromptly Cloud Editorial Team
2026-12-01
8 min read

Learn how to choose, size, test, and maintain few-shot examples that improve LLM accuracy without wasting context or cost.

Few-shot prompting can improve an LLM’s consistency, but adding examples blindly increases cost, context usage, and the risk of teaching the wrong pattern. This guide shows how to choose representative demonstrations, estimate how many examples to include, compare zero-shot and few-shot approaches, and test whether each example earns its place.

Overview

Few-shot prompting means giving a model a small set of input-and-output examples before asking it to process a new input. The examples act as an in-context specification: they show the labels, structure, level of detail, and edge-case behavior you expect.

The right number of examples is not a fixed rule. Start with zero examples, add one representative example, then add a small set only when testing shows a meaningful improvement. A useful working range is often two to eight examples for a narrow task, but the correct count depends on the task, example length, label ambiguity, model, context budget, and quality of the demonstrations. Treat that range as a testing starting point rather than a guarantee.

Few-shot prompting is most useful when the task has a clear output format but the instructions alone leave room for interpretation. Common cases include classification, information extraction, tone transformation, structured summaries, routing, and domain-specific terminology. It is less useful when examples are inconsistent, the task changes frequently, or the prompt becomes so long that the model has less room to process the actual input.

ApproachBest starting useMain trade-off
Zero-shotSimple, well-defined tasks with clear instructionsLowest prompt overhead, but more interpretation is left to the model
One-shotTasks that need one concrete format or tone exampleEfficient, but one example may overrepresent a particular case
Few-shotAmbiguous labels, varied inputs, or strict output conventionsCan improve consistency, but uses more tokens and requires careful selection
Retrieved examplesLarge task variation or domain-specific patternsCan be more relevant, but retrieval quality becomes part of the system

How to estimate

Use a repeatable selection workflow instead of guessing how many examples belong in a prompt.

  1. Define the success criterion. Decide what “better” means before writing examples. It might mean correct labels, valid JSON, complete fields, fewer refusals, consistent tone, or lower review effort. A prompt that sounds better is not necessarily more accurate.
  2. Build a small evaluation set. Collect inputs that represent normal cases, confusing cases, rare classes, and known failures. Keep the evaluation inputs separate from the demonstrations used in the prompt. This prevents you from judging a prompt only on examples it has already seen.
  3. Establish a zero-shot baseline. Write the task instructions and output schema without demonstrations. Run the same evaluation set and record the results. This tells you whether examples are adding value.
  4. Add one example. Choose a clear, typical case that demonstrates the desired input-output relationship. Test it against the same evaluation set. If one example fixes the main error pattern, more examples may not be necessary.
  5. Add examples by failure mode. Add a demonstration only when it teaches something the current prompt does not communicate. For example, add one example for a borderline label, one for a missing field, or one for a multi-label outcome.
  6. Stop when marginal value falls. Compare the improvement from each additional example with its token cost, latency, and maintenance burden. If an example does not improve the target metric or protect against a known failure, remove it.

A simple decision score can make this process easier:

Example value = expected error reduction − maintenance cost − prompt overhead

This is not a statistical formula. It is a review aid. An example may be worth keeping if it prevents a costly or risky error even when it changes the average score only slightly. Conversely, a long example that improves a narrow case but harms general cases should be revised or removed.

For production work, compare prompt versions on a fixed golden dataset and record results by category, not only as one overall score. A few-shot prompt can improve common cases while making a minority label worse. The prompt evaluation framework and LLM golden dataset guide provide useful structures for that testing workflow.

Inputs and assumptions

Example selection depends on more than the number of demonstrations. Review these inputs before deciding whether to use zero-shot, few-shot, or retrieved examples.

Task and label design

Examples cannot repair unclear labels. Define each label in plain language, identify boundaries between similar labels, and specify what to do when no label fits. For extraction, define whether missing values should be omitted, returned as null, or represented with a fixed phrase.

Representativeness

Choose examples that reflect the distribution and difficulty of real inputs. Include variation in length, vocabulary, formatting, and relevant user behavior. Do not select only polished or easy examples if production data is messy.

Coverage of edge cases

Use examples to clarify high-impact ambiguities, not to enumerate every possible input. Positive and negative pairs are particularly useful when two outcomes are easy to confuse.

Consistency of formatting

Keep delimiters, field names, capitalization, and ordering consistent. If the required output is JSON, every demonstration should use valid JSON with the same schema. Avoid mixing explanatory prose with machine-readable output unless that behavior is intentional.

Token and latency budget

Estimate the combined size of the system instructions, demonstrations, user input, retrieved context, and expected output. Available context limits differ by model and deployment, and practical performance can change as prompts grow. Leave room for the actual request and response rather than filling the entire available window with examples.

For a rough budget, calculate:

Prompt tokens ≈ instructions + sum of demonstration tokens + user input + retrieved context

Then compare the result with the model’s applicable context limit and your latency or cost requirements. Pricing and limits can change, so confirm them in the provider documentation when making a production estimate. For a broader request-cost workflow, see Prompt Cost and Latency Optimization.

Data safety

Use synthetic or redacted demonstrations when examples may contain personal, confidential, or regulated information. Examples are part of the prompt and may be logged or exposed through development tooling. The AI data privacy checklist can help structure a review before examples enter a shared prompt.

Worked examples

Example 1: Support-ticket classification

Suppose an application assigns one of three labels: billing, technical, or account. A zero-shot prompt may work for obvious requests, but “I was charged after cancelling” could be interpreted as either billing or account-related.

Start with a clear one-shot example:

Task: Assign exactly one label: billing, technical, or account. Return JSON only.

Input: I do not recognize the charge on my invoice.
Output: {"label":"billing"}

Input: {{ticket_text}}
Output:

If testing shows confusion between billing and account issues, add a contrastive pair:

Input: I cannot sign in because my password reset email never arrived.
Output: {"label":"account"}

Input: I was charged after I cancelled my subscription.
Output: {"label":"billing"}

These examples are more valuable than three near-identical billing tickets because they clarify the decision boundary. If adding a fourth example does not improve the held-out evaluation set, stop at three.

Example 2: Structured extraction

For extracting meeting details, include examples for a complete record and a missing field:

Return valid JSON with keys: date, time, location. Use null when a value is not provided.

Input: Meet me Tuesday at 2 PM in Room 4.
Output: {"date":"Tuesday","time":"2 PM","location":"Room 4"}

Input: The review is tomorrow at 9 AM.
Output: {"date":"tomorrow","time":"9 AM","location":null}

Input: {{meeting_text}}
Output:

The second demonstration teaches a behavior that instructions often leave underspecified: how to represent missing information. Do not add examples with different key names or informal comments unless the application expects them.

Example 3: Choosing retrieved examples

When inputs vary by product, jurisdiction, or internal terminology, a fixed few-shot set may become stale. A retrieval-based approach can select demonstrations similar to the current request. Use a stable instruction block, retrieve a small number of relevant examples, and test both retrieval quality and final model output.

Compare at least three configurations: no examples, a fixed curated set, and retrieved examples. Measure accuracy by category, along with prompt size and response latency. Retrieval is not automatically better; irrelevant examples can introduce patterns that are less appropriate than a shorter fixed prompt.

When to recalculate

Revisit the example set whenever the task, model, data, or operating constraints change. In particular, recalculate after adding or renaming labels, changing the output schema, introducing a new language or product area, modifying retrieval logic, or observing a new production failure mode.

Review the prompt after a model change as well. Models can differ in how they interpret formatting, follow schemas, and generalize from demonstrations. Re-run the same evaluation set rather than assuming that a prompt’s previous example count remains optimal. Also review token usage, response latency, and any provider pricing or context-limit changes before approving a larger demonstration set.

For maintainability, store demonstrations as versioned data rather than burying them in application code. Record why each example exists, which failure mode it addresses, and the evaluation result when it was added. Use a rollback process when a new example lowers performance for an important category; the prompt versioning workflow covers this type of change control.

A practical maintenance cycle is:

  • Monitor failed or low-confidence cases.
  • Group failures by cause instead of adding examples one at a time without analysis.
  • Propose the smallest demonstration change that addresses the group.
  • Test against both a fixed regression set and recent representative inputs.
  • Compare accuracy, consistency, prompt size, latency, and cost.
  • Deploy gradually and keep the prior prompt available for rollback.

The best few-shot prompt is rarely the longest one. It is the smallest tested set of clear, representative examples that resolves the task’s important ambiguities without crowding out the real input. Start with zero-shot, add examples tied to observed failures, and recalculate whenever your model, data, labels, or constraints change.

Related Topics

#few-shot prompting#in-context learning#prompt examples#LLM accuracy#prompt testing
P

Promptly Cloud Editorial Team

AI Development and Prompt Engineering Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.