One-Shot Prompting vs Few-Shot Prompting

La Lakshmi Priya Updated 05 Nov 2026
10 min read

Definitions One-shot prompting includes exactly one example of the task in the prompt.

Few-shot prompting includes several examples, typically between two and ten.

Both are forms of in-context learning (Lesson 26). The difference is not only the number of examples; it is what the model can learn from them. One example shows a single instance of the pattern. Several examples show which parts of the pattern stay the same and which parts change.

One-Shot Example Write a one-line description for each course.

Course: Python Basics Description: Learn variables, loops, and functions by building 5 small programs.

Course: Git and GitHub Description: Few-Shot Example Write a one-line description for each course.

Course: Python Basics Description: Learn variables, loops, and functions by building 5 small programs.

Course: Docker Essentials Description: Package and run any app in containers, from your laptop to the cloud.

Course: SQL for Analysts Description: Answer real business questions with SELECT, JOIN, and GROUP BY.

Course: Git and GitHub Description: What a Single Example Teaches A single example is very effective at communicating form: structure, length, labels, and general tone. But it has a fundamental limitation:

With only one example, the model cannot tell which features are essential and which are accidental.

Look at the one-shot example above. The description:

Starts with the verb "Learn" Lists three concepts Mentions a number ("5 small programs") Ends with "by building..." Which of these are rules? Should every description start with "Learn"? Should every one contain a number? The model cannot know. It often copies all of them.

Typical one-shot output:

Description: Learn commits, branches, and merges by building 5 small projects. The output follows the template almost word for word, including "Learn", three concepts, "by building", and even the number 5, which is not a fact about the Git course.

What Several Examples Teach In the few-shot version, the three examples differ in their opening verbs ("Learn", "Package", "Answer"), structure, and whether they include numbers. What they share is:

One line An action-oriented sentence Concrete topics or outcomes A practical focus By comparing examples, the model can separate the constant pattern from the variable details.

Typical few-shot output:

Description: Track every change to your code and collaborate through pull requests. The output follows the shared pattern without copying the specific wording of any single example.

Comparison Aspect One-Shot Few-Shot Examples 1 2 to 10 (typically) Communicates format Very well Very well Communicates variation Not at all Yes, through differences between examples Risk of copying High: wording, structure, and details are often copied Lower, especially with varied examples Label coverage in classification Shows only one label Can show every label and its boundaries Token cost Low Higher, grows with each example Effort to create Low Higher: examples must be varied and correct Best for Fixed templates and formats Style, classification, varied content, edge cases When One-Shot Is the Right Choice One-shot works best when the output should closely follow one fixed template, and copying the structure is exactly what you want.

Use Case 1: A Fixed Format Convert the meeting details into a calendar entry.

Details: Team sync with Priya and Arun on 5 Nov 2026 at 10:30 AM for 30 minutes, Google Meet. Entry: 2026-11-05 10:30–11:00 | Team sync | Priya, Arun | Google Meet

Details: Project review with Karthik on 12 Nov 2026 at 3 PM for one hour in Room 2. Entry: Expected output:

2026-11-12 15:00–16:00 | Project review | Karthik | Room 2 Why one example is enough: The format is strict and identical for all inputs. The example demonstrates the date format, 24-hour time, the end-time calculation, separators, and field order. There are no stylistic choices that could be copied inappropriately.

Use Case 2: Demonstrating an Unusual Instruction Sometimes a written rule is clear but unusual, and one example confirms how to apply it.

Rewrite the sentence in passive voice, keeping the original tense.

Sentence: The team released the update yesterday. Rewritten: The update was released by the team yesterday.

Sentence: Priya will review the pull request. Rewritten: Use Case 3: Low Token Budget In very high-volume applications, one well-chosen example may give most of the benefit at a fraction of the token cost of several examples.

When Few-Shot Is the Right Choice Use Case 1: Classification A single example shows only one label. The model learns nothing about how the other labels are applied or where the boundaries lie. Few-shot classification should include at least one example per label (Lesson 30).

Use Case 2: Style and Tone Style is a combination of many choices. A single example makes the model imitate that one text too closely; several varied examples show the style while allowing different wording.

Use Case 3: Inputs That Vary Widely If inputs vary in length, complexity, or type, one example cannot show how to handle the variety. Examples of a short input, a long input, and an unusual input show the full range.

Use Case 4: Edge Cases Examples can demonstrate how to handle missing information, mixed cases, or invalid input. These require additional examples beyond the typical case.

The Copying Problem Copying is when the model reuses the wording, structure, or specific details of an example in situations where they do not belong. It is most common with one-shot prompts, but it can also happen when all few-shot examples are similar.

Types of Copying Type Example Phrase copying Every description starts with "Learn..." Structure copying Every output has exactly three items because the example did Detail copying A number or name from the example appears in an unrelated output Length copying Outputs match the example's length even when the input requires more or less Detail Copying Is the Most Dangerous Phrase and structure copying make outputs repetitive. Detail copying makes outputs wrong: "5 small projects" appearing in the Git description is false information. In extraction tasks, a phone number or date from an example can appear in the output for an input that has none (Lesson 31 covers this in depth).

Reducing Copying Use several varied examples so no single wording dominates. State that examples illustrate the pattern, not the content: The examples show the format and style only. Do not reuse their wording or details. Use obviously different topics in examples from the real inputs, so copied details are easier to detect. Insert real facts into the input instead of expecting the model to supply them. Measuring Copying in Code You can detect excessive copying by measuring how similar each output is to the examples. Python's built-in difflib.SequenceMatcher gives a similarity ratio between 0 (completely different) and 1 (identical).

from difflib import SequenceMatcher

examples = [ "Learn variables, loops, and functions by building 5 small programs.", ]

outputs = { "Git and GitHub": "Learn commits, branches, and merges by building 5 small projects.", "HTML and CSS": "Learn tags, selectors, and layouts by building 5 small pages.", "Linux Basics": "Navigate the terminal and manage files and permissions with confidence.", }

def max_similarity(text: str, references: list[str]) -> float: """Return the highest similarity between text and any reference.""" return max(SequenceMatcher(None, text.lower(), ref.lower()).ratio() for ref in references)

THRESHOLD = 0.6

for course, output in outputs.items(): score = max_similarity(output, examples) flag = " <-- possible copying" if score >= THRESHOLD else "" print(f"{score:.2f} {course}: {output}{flag}") Possible output:

0.71 Git and GitHub: Learn commits, branches, and merges by building 5 small projects. <-- possible copying 0.69 HTML and CSS: Learn tags, selectors, and layouts by building 5 small pages. <-- possible copying 0.37 Linux Basics: Navigate the terminal and manage files and permissions with confidence. The exact scores depend on the texts; the values shown illustrate the pattern.

Code Explanation SequenceMatcher(None, a, b).ratio() compares two strings and returns their similarity. The first argument (None) means no characters are treated as "junk" to ignore. .lower() makes the comparison case-insensitive. max_similarity() compares one output with every example and keeps the highest score, because copying from any example counts. THRESHOLD = 0.6 is a starting value, not a standard. Adjust it by looking at real outputs: if clearly original outputs are flagged, raise it; if obvious copies are missed, lower it. Using the Result If many outputs are flagged, add more varied examples, add an instruction against reusing wording, or both. Then measure again to confirm the change helped.

Choosing Between One-Shot and Few-Shot Does every output follow one fixed template exactly? ├── Yes → One-shot is usually enough └── No ↓ Is this classification with more than one label? ├── Yes → Few-shot, at least one example per label └── No ↓ Is style, tone, or variety important? ├── Yes → Few-shot with varied examples └── No ↓ Do inputs vary widely or include edge cases? ├── Yes → Few-shot covering the variety └── No → Try one-shot; upgrade if copying or inconsistency appears As always, test both versions on the same inputs when the choice is not clear (Lesson 12).

Common Mistakes Mistake 1: Using One-Shot for Varied Content What it is: One example for tasks such as writing descriptions, replies, or captions.

Why it happens: One example seems enough to show the style.

What it causes: Repetitive outputs that copy the example's wording and details.

How to fix it: Use several varied examples, or state that only the format should be followed.

Mistake 2: One Example in Classification What it is: Showing one labeled example and listing the other labels in the instruction.

Why it happens: It seems the instruction covers the other labels.

What it causes: Possible bias toward the demonstrated label and no guidance on boundaries.

How to fix it: Provide at least one example for each label.

Mistake 3: Few Examples That Are All Alike What it is: Several examples with the same length, structure, and opening words.

Why it happens: Examples are written one after another in the same mindset.

What it causes: The same copying problems as one-shot prompting, at a higher token cost.

How to fix it: Deliberately vary length, structure, and wording across examples.

Mistake 4: Real-Looking Details in Examples What it is: Examples containing specific numbers, names, or dates that could plausibly apply to real inputs.

Why it happens: Realistic examples feel more helpful.

What it causes: Those details leak into outputs where they are false.

How to fix it: Make example details clearly specific to the example, and supply real facts through the input.

Best Practices Use one-shot for fixed templates. When copying the structure is the goal, one example is efficient.

Use few-shot for variety, style, and classification. Several examples separate the pattern from the details.

Vary your examples deliberately. Different openings, lengths, and structures reduce copying.

Tell the model what the examples are for. Format, style, or both, and not the specific content.

Measure copying when outputs should be original. Use a similarity check and adjust examples based on results.

Keep facts in the input. Do not rely on the model to fill in facts, or it may borrow them from examples.

Try It Yourself Exercise 1: Observe Copying Write a one-shot prompt that generates short testimonials for courses, with one example testimonial. Generate testimonials for five different courses and identify every phrase, structure, or detail copied from the example. Then add two more varied examples and repeat.

Exercise 2: One-Shot for a Strict Format Create a one-shot prompt that converts free-text expense notes ("Paid 450 for team lunch at Saravana Bhavan on 3 Nov") into a fixed line format of your choice. Test it on 10 notes. Decide whether a second example is needed, and if so, which kind of input it should demonstrate.

Exercise 3: Tune the Copying Detector Run the similarity script from this lesson on 10 outputs from a one-shot prompt and 10 from a few-shot prompt. Compare the average similarity scores and adjust the threshold so that it flags the outputs you judge to be copies.

0 Comments

Reviewed before they appear

No comments yet.

Ask about this post
AI Ask about this post

Ask questions about One-Shot Prompting vs Few-Shot Prompting and get answers drawn from it.

Signed-in readers only.