Few Shot Prompting (original) (raw)

Last Updated : 30 Apr, 2026

Few‑shot prompting is a technique in AI where a model is given a small number of examples within the prompt to guide its response. By learning from these examples, the model can better understand the task and generate more accurate and relevant outputs without additional training.

Working

Few-shot prompting is a technique where a large language model (LLM) is guided by providing a small number of examples directly within the prompt. These examples demonstrate the desired task, enabling the model to generalize and produce accurate outputs without explicit training.

1. User Query Initialization

The process starts when the model receives a user query, which serves as the input for the task. This query establishes the context and defines what the model needs to do such as classification, translation or sentiment analysis.

2. Example Source (Static or Dynamic)

Few-shot prompting uses examples to guide the model, which can either be predefined or dynamically retrieved based on the query.

A vector store enables meaning-based retrieval rather than exact keyword matching, allowing the system to select the most relevant examples and improve overall model performance.

3. Retrieval of Relevant Examples

If dynamic retrieval is used, the system performs semantic matching to find the most relevant examples:

In advanced systems, Retrieval-Augmented Generation (RAG) may be used to improve retrieval quality by ensuring that the selected examples are highly relevant to the query context.

4. Prompt Construction

Here the system builds a well-structured prompt by combining examples and the user query to guide the model toward the desired output.

**For Example: Classify the sentiment of the following sentences:

Sentence: "I love this product"
Sentiment: Positive

Sentence: "This is the worst experience"
Sentiment: Negative

Sentence: "This app is really easy to use"
Sentiment: Positive

This structured prompt helps the model recognize patterns from the examples and apply them to the user query. A clear and well-formatted prompt significantly improves the accuracy and consistency of the generated output.

5. Model Processing

LLM processes the constructed prompt by using its internal knowledge and the provided examples.

Model combines prior knowledge with in-context examples to understand the task and generate an appropriate response. This enables effective performance without requiring additional training.

6. Output Generation

Here the model produces the response by applying the patterns learned from the examples to the user query. The output is generated in the expected format, completing the task such as classification, translation or text generation.

Examples of Few-Shot Prompting

Here are a few prompt examples to demonstrate how Few Shot Prompting works:

Example 1: Text Generation

**Examples Provided:

1. The sky is painted bright, the sun begins to fall, Golden hues stretch far, lighting up the world for all.
2. As the sun sets low, the stars begin to glow, The evening breeze whispers soft and slow.

**AI Output:

As the sun fades away, the sky turns to gold,
The colors blend, a story untold.
A calm breeze flows, the air turns cool,
The world sighs gently, under the moon’s rule.

The model learns the style, tone and structure of the poems from the examples and generates a new poem following similar patterns. This shows how few-shot prompting enables creative tasks without explicit training.

Example 2: Classification Task

**Examples Provided:

1. Smartphone: A device used for communication, browsing the internet and running apps.
2. Laptop: A portable personal computer with a keyboard and screen, used for work, browsing and entertainment.

The model compares the query with the provided examples and identifies the closest match based on semantic similarity and key features. This shows how few-shot prompting works effectively for classification tasks.

Strategies

Applications

Advantages

Limitations