AI glossary: Prompting

What Is Few-Shot Prompting? Meaning, Examples and How Many Shots to Use

Satvik ParamkushamUpdated October 5, 20265 min read

Definition

Few-shot prompting is a technique where you include a small number of worked examples, usually two to five input and output pairs, inside the prompt so the AI model copies the pattern, format and style for your real question.

In Hindi: Few-shot prompting matlab AI ko prompt ke andar 2-3 solved examples dikhana, taaki woh same pattern follow karke aapke sawaal ka jawab de.

What is few shot prompting in AI?

Few shot prompting in AI means you show the model a few examples of the task done correctly, then ask it to do the same for a new input.

Think of how a teacher explains a new type of maths problem. She solves two on the board, then gives you the third. Few-shot prompting does the same for a large language model. Each example is called a "shot", so two examples is a two-shot prompt.

The important part: the model is not retrained. Its parameters stay exactly the same. It simply reads the examples inside its context window and picks up the pattern for that one conversation. Researchers call this in-context learning.

Few-shot prompting sits one step above zero-shot prompting, where you give only an instruction and no examples.

Few shot prompting example (with 3 shots)

A few shot prompting example has three parts: a short instruction, a few solved input and output pairs, and the new input left unanswered.

Say you run a college canteen app and want customer messages tagged with your own labels:

Tag each message as MENU, PAYMENT or COMPLAINT.

Message: Is veg biryani available today?
Tag: MENU

Message: My UPI payment got deducted but the order failed.
Tag: PAYMENT

Message: The samosa was cold and the tea was spilled.
Tag: COMPLAINT

Message: Can I pay with a canteen card instead of cash?
Tag:

The model will very likely answer PAYMENT, in exactly one word, because the examples showed both the labels and the format. Without the examples, it might reply with a full sentence or invent a label like "Query".

Few-shot works for formats too. Two examples of a product description written in a friendly, 40-word style will shape the third far better than the instruction "be friendly and short".

Few shot prompting: how many examples should you use?

Most tasks need two to five examples, and you should add more only if testing shows the output improving.

  1. Start with 2 or 3. Enough to show the pattern without bloating the prompt.
  2. Cover the variety. Include each label or case at least once, plus one tricky edge case.
  3. Keep the format identical. Same labels, same spacing, same order every time. Models copy inconsistency too.
  4. Watch the cost. Every example adds tokens, which means longer prompts and higher API bills.

Order and balance matter. If four of your five examples are COMPLAINT, the model may lean towards that label. Mix them up.

My tip from teaching beginners: write your examples by hand instead of copying the first ones you find. Clean, carefully chosen examples beat a long list of messy ones.

Few shot prompting vs chain of thought

Few-shot prompting shows the model examples of answers, while chain-of-thought prompting asks the model to show its reasoning steps before the answer.

They solve different problems:

  • Few-shot fixes format, labels and style. Use it when the model does not know what your output should look like.
  • Chain-of-thought fixes reasoning. Use it when the model rushes to a wrong answer on maths or logic.

They also combine well. The original chain-of-thought research used few-shot prompts where each example included worked-out reasoning, not just the final answer. So "few-shot chain-of-thought" means your examples demonstrate the thinking, and the model copies that habit.

Which research paper introduced few shot prompting?

The paper most linked to few shot prompting is "Language Models are Few-Shot Learners" by Brown and colleagues at OpenAI, published in 2020, which introduced GPT-3.

The paper showed that a large enough model (GPT-3 had 175 billion parameters) could perform many tasks just from examples placed in the prompt, without any extra training. It compared three settings side by side: zero-shot, one-shot and few-shot. On many tasks, adding examples improved results, and the benefit tended to be larger for bigger models.

That paper made prompting a serious skill. Before it, adapting a model to a new task usually meant fine-tuning. After it, many tasks could be handled by writing a better prompt. Few-shot prompting is now a standard topic in prompt engineer interviews.

Frequently asked questions

What does few shot prompting involve?

Few-shot prompting involves giving the AI model a small number of example inputs with their correct outputs inside the prompt, followed by a new input. The model uses those examples as a guide to produce an answer in the same pattern and format.

Few-shot prompting provides examples to the model to improve what?

It mainly improves the accuracy and consistency of the output for that specific task: the right labels, the right format and the right style. It does not add new knowledge to the model or change its training.

What is few shot prompting in GitHub Copilot?

In GitHub Copilot, few-shot prompting means showing it one or more examples of the code pattern you want, such as two similar functions or test cases, before asking for the next one. Copilot then follows that style, naming and structure.

Is few shot prompting the same as fine-tuning?

No. Few-shot prompting puts examples in the prompt and the model's weights never change. Fine-tuning actually trains the model on many examples, so the new behaviour stays without needing examples in every prompt.

What is few shot prompting useful for?

It is useful for classification with custom labels, extracting data in a fixed format, matching a writing style and handling tasks where a plain instruction keeps producing the wrong shape of answer.

References