> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Purpose of Few Shot Examples in Prompting

> Explains that few-shot examples in prompts steer LLMs’ output format, tone, and behavior via in-context learning without changing model weights or reducing inference cost.

Question 6.

In prompt engineering for LLMs, what is the primary purpose of using few-shot examples?

* To increase the model's vocabulary?
* To guide the model's response format and style?
* To reduce the computational cost of inference?
* Or to fine-tune the model weights in real time?

Answer: Few-shot — To guide the model's response format and style.

Few-shot examples supply in-context demonstrations that steer the LLM toward the expected format, tone, and approach for a task. They do not alter the model's internal weights or vocabulary and do not reduce inference cost. Instead, they provide examples that the model uses at inference time to infer the desired mapping from inputs to outputs.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/wB9PojHAKOj5Y3VV/images/NVIDIA-Generative-AI-LLMs-Associate-Certification/Core-Machine-Learning-and-AI-Knowledge/Purpose-of-Few-Shot-Examples-in-Prompting/few-shot-examples-prompt-engineering-llms.jpg?fit=max&auto=format&n=wB9PojHAKOj5Y3VV&q=85&s=9cd1497592291fe96bfc1a2a303e13f6" alt="The image contains a question and answer about the primary purpose of using &#x22;few-shot&#x22; examples in prompt engineering for LLMs, citing guiding the model's response format and style as the purpose." width="1920" height="1080" data-path="images/NVIDIA-Generative-AI-LLMs-Associate-Certification/Core-Machine-Learning-and-AI-Knowledge/Purpose-of-Few-Shot-Examples-in-Prompting/few-shot-examples-prompt-engineering-llms.jpg" />
</Frame>

Example

The following few-shot prompt gives the model three demonstration pairs that map plain-English instructions to shell commands. The fourth entry is the new instruction (the query). The model should follow the demonstrated pattern and produce the corresponding command:

```bash theme={null}
# Example few-shot prompt: instruction -> command pairs
Instruction: List files in the current directory
Command: ls

Instruction: Show the current working directory
Command: pwd

Instruction: Create a directory named projects
Command: mkdir projects

# Target query (model should infer the pattern and respond with a command)
Instruction: Remove the file old.txt
Command:
```

Given those demonstrations, the model should infer the mapping from "Instruction" to "Command" and complete the last "Command" with the correct shell command, for example:

```bash theme={null}
rm old.txt
```

<Callout icon="lightbulb" color="#1CB2FE">
  Few-shot prompts provide examples that shape the model's output format and style at inference time. They do not train the model or change its weights; they simply bias the model toward the pattern shown in the prompt.
</Callout>

Quick comparison

| Option                                      | What it does                                                                          | Correct? |
| ------------------------------------------- | ------------------------------------------------------------------------------------- | -------- |
| Increase the model's vocabulary             | Not affected by few-shot prompts; vocabulary is defined by the pre-trained model      | No       |
| Guide the model's response format and style | Provides in-context examples so the model mimics the demonstrated structure and tone  | Yes      |
| Reduce computational cost of inference      | Few-shot examples can increase prompt length and cost per query rather than reduce it | No       |
| Fine-tune model weights in real time        | Few-shot prompting is not training; it does not update model parameters               | No       |

Further reading and references

* [In-context learning and few-shot prompting — OpenAI blog](https://openai.com/blog/instruction-following)
* [Prompting strategies and best practices — Practical guides on prompt engineering](https://learnprompting.org/)
* [Research overview: Few-shot learning and in-context learning](https://arxiv.org/abs/2103.10385)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/nvidia-generative-ai-llms-associate-certification/module/875d98e8-3b09-4f35-b877-2758b84443ca/lesson/8da9d9e9-78bf-45aa-b511-bb4b1244c34f" />
</CardGroup>
