Przejdź do treści
promptowy.com / AI Glossary / Few-Shot Prompting
Prompting

Few-Shot Prompting

Few-shot prompting is an AI technique where you provide a small set of input and output examples in your prompt to demonstrate the exact pattern you want.

Few-shot prompting is an AI technique where you provide a language model with a handful of completed examples within your instruction before asking it to handle a new task. Instead of relying solely on abstract rules, you show the system two, three, or four demonstrations of inputs paired with their desired outputs. The model detects the underlying pattern, matches the structure, and applies the same logic to your final request.

Think of it like training a new assistant at an independent estate agency in Bristol or a hardware shop in Austin. Rather than having them read a lengthy handbook on filing invoices, you simply hand them two properly completed forms. By seeing the finished product, the assistant immediately grasps which boxes to fill, what shorthand to use, and how to format dates without needing an exhaustive explanation.

How few-shot prompting works behind the scenes

Large language models are fundamentally pattern-completion engines. When you give a model an instruction with no demonstration, known as zero-shot prompting, the system has to guess the tone, schema, and depth you expect. It relies on its broad background training, which often leads to verbose or unpredictable answers.

When you include few-shot demonstrations, you change the probability landscape inside the model's active working memory. The system detects the rhythm of the text: it notes the labels you use, the length of your answers, the punctuation style, and the reasoning steps. It does not update its underlying weights or learn permanently; instead, it matches the immediate context you provided to generate the next logical step in the sequence.

A real-world example: Customer feedback triage

Consider a busy independent bicycle repair shop with locations in Manchester and Seattle. The shop receives dozens of customer emails every day, ranging from urgent brake repairs to praise for mechanics. To route these messages automatically, the owner needs the AI to extract three items: the core issue, the department, and the priority level.

Writing rules for tone and sentiment can quickly become confusing. With few-shot prompting, the owner sets up a repeatable template:

  • Input: "My rear derailleur snapped on the commute this morning. I need the bike back by Friday for an event."
    Output: Issue: Broken derailleur | Department: Workshop | Priority: High
  • Input: "Just wanted to say thanks to Sarah for tuning my gears yesterday, brilliant service!"
    Output: Issue: Staff compliment | Department: Front Desk | Priority: Low
  • Input: "Do you have inner tubes for a 29-inch wheel in stock right now?"
    Output: Issue: Stock check | Department: Parts | Priority: Medium

When the owner appends a new, unseen customer message at the bottom, the model does not write a conversational essay or offer unprompted advice. It immediately outputs the exact three-part format shown above.

When to choose few-shot over detailed descriptions

Few-shot prompting is one of the most reliable methods in prompt engineering, especially when precision is critical. It consistently outperforms lengthy paragraphs of instructions in several scenarios:

  1. Strict formatting: When you need data returned as clean JSON, pipe-separated lists, or concise summaries without conversational filler.
  2. Domain-specific jargon: When working with local UK council planning terms, US medical billing shorthand, or regional legal phrasing where words carry exact meanings.
  3. Tone matching: When writing social media updates or marketing newsletters that must mimic an existing brand voice rather than sound generic.
  4. Complex classification: When sorting user queries into non-standard categories that a general AI model might otherwise blur together.

Common mistakes to avoid

The most frequent error is introducing inconsistency across your examples. If your first demonstration uses bullet points, your second uses a single sentence, and your third uses abbreviations, the model will struggle to determine which pattern matters. Your examples must act as rigorous templates.

Another common trap is using misleading or low-quality examples. Because the model anchors heavily on the demonstrations, any factual error, typo, or bias in your samples will propagate straight into the final answer. Keep your examples simple, clean, and representative of the real inputs your system will encounter in daily operation.

Frequently asked questions

How many examples make a prompt few-shot?

Typically, two to five high-quality examples are enough to establish a clear pattern. Adding more examples can slightly improve accuracy, but it also consumes more space in the model's context window.

What is the difference between few-shot prompting and fine-tuning?

Few-shot prompting provides examples in the temporary chat prompt without modifying the AI system itself. Fine-tuning is a separate process that permanently updates the model's internal parameters using thousands of training records.

Does few-shot prompting work on smaller AI models?

Yes, smaller models often benefit even more from few-shot prompting than larger systems do, because clear examples eliminate ambiguity and keep the model focused on a rigid structure.

Can bad examples ruin few-shot performance?

Yes. If your examples contain inconsistent formatting, typos, or wrong answers, the model will copy those mistakes directly into its output.

← All terms in the AI Glossary

🛒 Sklep Kinetyka CapCut Pro 460 zł/rok Lovable Pro 450 zł/rok Replit Core 119 zł/rok Zobacz wszystko →
× ‹ powiększenie ›