Use Few-Shot Examples Effectively
Explore zero-shot vs few-shot prompting, and how to use examples to teach the model desired output patterns and styles.
You can guide the model by including examples in your prompt that demonstrate the ideal response. The model learns from these examples by recognizing patterns and structures, then applies that understanding to generate its own output. Prompts with a few examples are known as few-shot prompts, while those with none are called zero-shot prompts. Few-shot prompts are particularly useful for shaping the tone, format, scope, and overall structure of the model’s replies. Using clear, diverse examples helps the model stay focused and deliver more accurate results.
It’s generally best to include a few examples in your prompt. Without them, the model’s responses may be less precise. In fact, if your examples are well-chosen and illustrative, you may not even need additional instructions at all.
Zero-shot vs few-shot prompts
The zero-shot prompt below instructs the model to select the most suitable explanation.
Example Prompt:
Response:
If your goal is to get brief responses from the model, you can add examples in your prompt that highlight concise answers.
In the next prompt, two sample explanations are given, showing a clear preference for shorter responses. As a result, the model is influenced by these examples and selects the more concise explanation (Explanation 2), unlike the earlier case where it chose the longer one (Explanation 1).
Example Prompt:
Response:
Determine the Right Number of Examples
To get the best outcome, try different numbers of examples in your prompt. Models like Gemini can usually recognize patterns with just a few examples, but you might need to test how many are needed to achieve the result you want. Be cautious though—adding too many can cause the model to mimic the examples too closely instead of generalizing properly.
Use examples to show patterns instead of antipatterns:
It’s more effective to include examples that demonstrate the kind of response you want, rather than showing what not to do. Highlighting good examples helps the model follow the intended pattern more accurately.
🚫 Negative pattern:
✅ Positive pattern:
Keep Formatting Consistent Across Examples
To ensure the model produces the desired output, your few-shot examples should all follow the same structure and formatting. Since the purpose of few-shot prompting is to guide the model’s response format, it’s important to maintain uniformity in elements like XML tags, line breaks, whitespace, and separators between examples. Inconsistencies might lead to unpredictable results.
📝 Summary:
Use prompt-response examples to teach the model how to respond.
Focus on showing clear examples of what you want, not what to avoid.
Test different numbers of examples to see what works best—too few may not help, while too many could limit the model’s flexibility.
Always keep the formatting consistent across all examples to guide the model accurately.
Was this page helpful?