ADVERTISEMENT

Few-shot prompting explained: how AI learns with minimal examples

What is few-shot prompting
Greta Čeponė
Greta Čeponė Senior Tech Content Writer
May 2, 2025 4 min read

How few-shot prompting works

How few-shot prompting works
What is a large language model?

A large language model (LLM) is a type of artificial intelligence that’s trained to understand and generate human-like text. It reads huge amounts of data, like books, websites, and articles, and learns how words and sentences usually go together. That’s how it can answer questions, write emails, and summarize text by using patterns it has seen before.

A comparison of prompting techniques

PromptExample
Zero-shot promptingIs this review positive or negative? “I love this product, it’s perfect”
One-shot promptingDefine this review:
“Not worth the money”
Positive review example:
“I love this product, it’s perfect”
Few-shot promptingDefine this review:
“The battery life is short, but otherwise it works well”
Negative review example:
“Not worth the money”
Positive review example:
“I love this product, it’s perfect”
Multi-shot promptingNegative review examples:
“Not worth the money”
“Arrived late and was damaged”
Positive review examples:
“I love this product, it’s perfect”
“Exceeded my expectations in every way”
“The screen quality is fantastic”
Mixed review examples:
“The battery life is short, but otherwise it works well”
“Setup was confusing, but customer service helped”
“The manual was missing, but I figured it out”
Is this review positive or negative?
“It stopped working after a week”
PromptExample
Chain-of-Thought (CoT)If 3x+5=50, find x. Explain the steps.
Zero-shot CoTHow much does a $50 item with 20% off cost? Explain the steps.
Tree-of-ThoughtExplain AI ethics by exploring job risks, creative benefits, and regulations.
PromptExample
Role promptingAs a biologist, explain photosynthesis in under 100 words.
Template fillingCreate 5 Instagram captions for my brand's launch, emphasizing cost-per-wear and high-quality.
ComparativeCompare Python vs R for data science in a table format.

The evolution of prompting techniques

ADVERTISEMENT

How prompting changed over time

  • Before 2019: Early AI models, like neural networks and RNNs, helped build the foundation for modern language models. The introduction of transformer models, like the one behind GPT, completely changed how prompts and responses worked.
  • 2019-2020: GPT-2 and GPT-3 introduced in-context learning. Instead of retraining models from scratch, people began focusing on creating better prompts, including few-shot prompting, to get more accurate results.
  • 2021-2022: Prompting techniques improved. One new method was Chain-of-Thought prompting, in which the model explains its reasoning step by step before answering. This method is often used to solve math problems or make decisions.
  • 2023-2025: Prompt engineering became its own field. Teams started using tools like LangChain, PromptLayer, and Helicone to manage and test different prompts, track results, and make their workflows more efficient.

How to write effective few-shot prompts

  1. Start with a clear goal. Before you start, understand the outcome you want. This will help you choose the best examples and evaluate how to improve your query.
  2. Choose relevant examples. Use input and output examples that are similar in style and format, because LLMs follow patterns very closely. This includes the use of spaces, punctuation, and tone.
  3. Don’t overload the prompt. It’s important to provide enough information, but not unnecessary details. Too much information can be confusing and result in inaccurate results.
  4. Simplify your instructions. Before querying, reread your prompt and see if it can be simplified and broken down into more digestible steps.
  5. Test and edit your prompt. Your first try may not always provide the best results. If you need improvements, analyze how AI interprets your examples, if there is a consistent error, and adjust the prompt. Even small changes in your phrasing can make a difference in your results.

Common mistakes to avoid

  • Overloading the prompt. Adding too many examples can confuse the model or push important context beyond the prompt limit. Two to five is usually enough, since the model can already catch on to the requirements with them.
  • Inconsistent formatting. If one example has punctuation and the next doesn’t, or if the structure differs, the model will not know which example to follow. Use the same style across all examples.
  • Unclear goal. If it’s not obvious what you want the model to do, you’re likely to get vague or mismatched answers. Start with simple instructions and adjust based on the responses you receive.
  • Mixing styles or tones. Switching between formal and casual examples, or jumping between unrelated topics, can throw off the model. Keep your examples aligned in tone and topic.
  • Examples that don’t match the task. If your examples are not closely related to what you want, the model might pick up the wrong patterns. Be specific and take your time picking examples for the task.

When is few-shot prompting not the best approach?

Conclusion

ADVERTISEMENT