Few-shot prompting is a way of guiding an AI model by including several examples directly in the prompt before asking the model to handle a new case. Instead of only describing the result you want, you show the model sample input and output pairs.
For instance, you could include several customer messages labeled “Action required” or “Information only,” then ask the model to classify a new message. This approach helps when written instructions alone don’t make the categories, format or style clear.
Key Takeaways
- What it is: Few-shot prompting uses several examples in a prompt to demonstrate a task or a response pattern.
- How it works: The examples guide the model within the current request. They do not change the underlying parameters or retrain the model.
- Why it helps: It can make repeated tasks more consistent, but the examples need to be relevant and clear, and they need to be tested.
What is few-shot prompting?
Few-shot prompting means giving a large language model (LLM) several examples before asking it to generate a response. A large language model is an AI system trained to process and generate text. The examples in the prompt show how to do the task, how to format the result or how to follow a specific style.
A simple example:
“`text
Message: “Can you send the updated invoice by Friday?”
Category: Action required
Message: “The office will be closed next Monday.”
Category: Information only
Message: “Please review the attached contract and send me your comments.”
Category:
“`
The model uses the first two input-output pairs as a pattern, then classifies the new message. The examples only guide the response to the current request. They don’t permanently teach the model a new rule. DataCamp describes few-shot prompting as providing a small number of task examples before generating a response.
How does few-shot prompting work?
Few-shot prompting supplies examples so the model can apply a pattern to new input without changing the model’s underlying parameters.
1. State the task. Explain what the model needs to do, such as classifying emails or extracting information.
2. Provide examples. Pair several inputs with the outputs you want.
3. Give the new input. Ask the model to apply the pattern to a case that doesn’t appear in the examples.
4. Check the result. Evaluate the output against the requirements of the task.
The examples don’t become new training data in the usual sense. They are part of the prompt the model considers when generating a response. That is why few-shot prompting can adapt a general-purpose model to a narrower task without changing its parameters. DataCamp explains the difference between prompt-based adaptation and parameter changes.
Say you want to classify support emails. You can include two or three labeled messages, then add the message you need handled:
“`text
Classify each message as Billing, Technical support or Account access.
Return only the category name.
Message: “I was charged twice for my subscription.”
Category: Billing
Message: “The dashboard shows an error when I upload a report.”
Category: Technical support
Message: “I can’t log in because I no longer have access to my old phone number.”
Category:
“`
The examples show both the categories and the output format, which helps the model understand the task better than a single instruction would.

Zero-shot, one-shot and few-shot prompting
These terms describe how many examples a prompt contains. They don’t refer to different types of AI models.
| Prompting method | Number of examples | Typical prompt structure |
|---|---|---|
| Zero-shot prompting | None | Instructions, then the new input |
| One-shot prompting | One | Instructions, one example, then the new input |
| Few-shot prompting | Several | Instructions, several examples, then the new input |
With zero-shot prompting, you might ask: “Classify this email as Billing, Technical support or Account access.” The model gets instructions but no examples.
With one-shot prompting, you add one labeled example. This can be enough for simple tasks that are easy to demonstrate. Few-shot prompting provides several examples, which helps the model recognize categories, formatting rules or differences between similar cases. IBM also distinguishes the three approaches by the number of examples: zero-shot has none, one-shot has one and few-shot has several. See IBM’s explanation of few-shot prompting.
A simple few-shot prompt example
The following example sorts work emails into three categories:
“`text
You classify work emails into one of the following categories:
– Action required: the recipient needs to do something
– Information only: the message shares information but doesn’t ask for action
– Follow-up: the message continues an ongoing conversation or asks for a status update
Return only the category name.
Email: “Please approve the revised project budget by Thursday.”
Category: Action required
Email: “The quarterly all-hands meeting will take place on September 12.”
Category: Information only
Email: “I wanted to check whether you’ve had a chance to look at the proposal.”
Category: Follow-up
Email: “Can you confirm which version of the report we should use for the client meeting?”
Category:
“`
The prompt has four parts:
- Task instructions: State what the model needs to do.
- Category definitions: Clarify what each label means.
- Examples: Pair emails with the desired category.
- New input: The final email to be classified.
You can use the same structure to classify support requests, extract data fields from invoices or write short replies in an approved tone. The examples need to show exactly the pattern you want the model to follow. DataCamp identifies input-output pairs, consistent formatting and relevance to the task as common features of useful demonstration examples.
When should you use few-shot prompting?
Use few-shot prompting when examples make a task clearer than written instructions alone, especially for tasks with repeated patterns or organization-specific conventions.
Some good use cases:
1. Classification: Sorting customer messages into categories such as billing, shipping or technical support.
2. Structured extraction: Showing how to turn unstructured notes into fields such as date, owner, priority and next step.
3. Consistent formatting: Demonstrating how to produce a short table, a JSON-style record, a bulleted list or a fixed report section.
4. Matching tone and style: Using approved emails or marketing copy when the wording needs to follow a specific style.
5. Code or text conversion: Showing how to convert a source format into the required output format.
If a team needs short, calm customer service replies, it can include several approved replies along with the original customer messages. The examples help the model follow the desired phrasing and level of detail. Few-shot prompting is also used for tasks such as sentiment analysis, named entity recognition, dialogue and code generation. IBM provides examples of these application areas.
Not every task needs few-shot prompting. If a clear instruction already produces a suitable result, adding examples may only make the prompt longer.
How to choose useful examples
Choose examples that are relevant, consistent and representative of real inputs, so they help the model recognize the pattern you want instead of adding uncertainty.
1. Draw examples from the real task. For support messages, use support messages rather than unrelated text.
2. Pair each input with a clear output. The model needs to see what a correct result looks like.
3. Use the same structure. Keep field names, separators and output style consistent.
4. Show meaningful differences. Demonstrate how similar cases should receive different labels.
5. Include important edge cases when needed. If urgent requests are handled differently from routine ones, illustrate that difference.
6. Remove contradictory examples. Similar inputs with inconsistent labels make the intended rule harder to recognize.
Compare these two presentations:
“`text
Examples with inconsistent structure:
Email: “The invoice has an error.”
Result: Billing issue
Text: “Can you help me log in?”
Output: Account access
Message: “Where is my order?”
Category: Shipping
“`
“`text
Consistent examples:
Email: “The invoice has an error.”
Category: Billing
Email: “Can you help me log in?”
Category: Account access
Email: “Where is my order?”
Category: Shipping
“`
The second version uses the same field names and label format, which makes the intended structure easier to recognize. The examples should also match the level of detail and language you need in the output. DataCamp recommends using relevant input-output pairs and consistent formatting when creating demonstration examples.
How many examples should you include?
There is no optimal number of examples for every task, model or prompt. Start with a small set of relevant examples, then test whether adding more actually fixes a real problem.
For a simple email classification task, you might start with a few examples that cover the main categories. If the model confuses two categories, add examples that clearly distinguish them. If extra examples don’t improve the results, remove them to keep the prompt shorter.
One prompting guide suggests about two to five examples as a practical range, while noting that the benefit may diminish as you add more. This is that source’s own recommendation, not a rule that applies in every case. See PromptHub’s recommendation and caveats.
Examples share the context space with instructions, conversation history, documents and other content. As a result, long examples take room from everything else and, depending on the tool, may increase processing costs or reduce the space available for the response. Comet discusses this context budget trade-off.
How to test and improve a few-shot prompt
Test the prompt on new inputs that weren’t used as examples to determine whether the model can apply the pattern or is just echoing familiar examples.
1. Set aside test inputs. Keep some representative cases out of the prompt.
2. Run the prompt. Use the same instructions and examples for each test input.
3. Compare the outputs with the expected results. Check labels, format, completeness and tone.
4. Find the cause of errors. The labels may be unclear, edge cases may be missing, examples may contradict each other or the instructions may be vague.
5. Change only one thing at a time. Swap one example, clarify one label or adjust the output format.
6. Rerun the same tests. Confirm the change works and doesn’t create new problems.
If your email classifier keeps putting “Please confirm whether the payment has been received” into a new billing request category instead of follow-up, add or revise examples to clarify that difference. Adding more unrelated examples won’t necessarily fix the error.
This is a practical way to check your prompt, not a guarantee of reliability. For high-impact decisions, verify the output against authoritative information and have a person take responsibility for the final decision.
Few-shot prompting vs. fine-tuning
Few-shot prompting puts examples in the prompt; fine-tuning uses examples in a separate training process.
| Aspect | Few-shot prompting | Fine-tuning |
|---|---|---|
| Where examples are provided | Inside the prompt | In a separate training process |
| Effect on model parameters | No change to parameters | Adjusts the model through training |
| Best suited for | Quick task guidance and experimentation | More stable adaptation for a recurring use case |
| How to make changes | Edit the prompt or the examples | Run or request another training process |
| Main trade-off | Uses prompt space | Requires more data, setup and evaluation |
Pasting several approved emails into a request is few-shot prompting. Training a custom model on a set of examples is fine-tuning. Few-shot prompting lets you quickly try out a task pattern; fine-tuning is a separate option worth considering when a recurring use case needs more stable adaptation. The two are not interchangeable. DataCamp distinguishes few-shot prompting from changing a model’s underlying parameters.
What are the limitations of few-shot prompting?
Few-shot prompting helps clarify a task but doesn’t guarantee accurate or consistent results.
1. Poor examples can teach the wrong pattern. Mislabeled or unclear examples can affect the output.
2. Examples can miss important cases. The model may struggle when new input differs from the examples.
3. Complex tasks need more than pattern recognition. Examples can’t fix vague requirements or incomplete information.
4. Results depend on the model. Different models may respond differently to the same set of examples.
5. Examples take up context space. Long examples compete for room with instructions, documents, conversation history and the requested output.
6. Plausible-looking output can still be wrong. A well-formatted classification or draft still needs review if mistakes could have significant consequences.
Effectiveness depends on the complexity of the task, the quality and relevance of the examples, the quality of the prompt and the capabilities of the foundation model. DataCamp covers these factors when discussing the limits of few-shot prompting.
At work, don’t put confidential customer information, passwords, API keys, private contracts or other sensitive data into a prompt unless your organization has approved the tool and its data handling terms. Whether a provider uses submitted content to train its models is a separate question from how long it retains or logs that content. Check both policies before using real business data.
Checklist for beginners
Use this checklist when creating your first few-shot prompt:
- State the task in one clear instruction.
- Define the categories or required fields if they could cause confusion.
- Add a small set of relevant input-output examples.
- Keep the format and labels of the examples consistent.
- Include examples that show important differences or edge cases.
- Specify the required output format.
- Test the prompt on new inputs that weren’t used as examples.
- When refining, change only one instruction or one example at a time.
- Review important outputs; examples don’t guarantee results.
- Remember that examples guide the current request; they don’t retrain the model.
Few-shot prompting is a prompt engineering technique: it shows an AI model what a task looks like instead of relying on instructions alone. Use it when examples clarify the pattern you want, keep them focused and test the results before relying on the output for important work.
For a fuller picture of this topic, you can also read our articles on what prompt engineering is, how to use constraints in prompts, iterative prompting and what context engineering is.
Frequently asked questions about few-shot prompting (FAQ)
What is few-shot prompting?
Few-shot prompting means giving a large language model (LLM) several examples before asking it to generate a response. A large language model is an AI system trained to process and generate text. The examples in the prompt show how to do the task, how to format the result or how to follow a specific style.
How does few-shot prompting work?
Few-shot prompting supplies examples so the model can apply a pattern to new input without changing the model’s underlying parameters.
What are zero-shot, one-shot and few-shot prompting?
These terms describe how many examples a prompt contains. They don’t refer to different types of AI models.
What does a simple few-shot prompt look like?
The following example sorts work emails into three categories:
Was this article helpful?
Learn AI Mindset researches and fact-checks every article so you can understand and use AI well. If this one was useful, you can support us voluntarily so we can keep writing more like it.
Completely optional. Every article stays free to read whether or not you support us.
Support Learn AI Mindset on Ko-fiPayment is handled by Ko-fi and PayPal. We never see or store your card details.