Prompt Engineering Fundamentals / Prompting Techniques

Few-Shot Prompting

Beginner [2/5]
In-context learning Multi-shot learning Demonstration-based prompting

Definition

Few-shot prompting involves providing 2-5 examples of the task you want performed before asking the model to do it. The examples demonstrate the pattern, format, and style you expect.

This technique leverages the model's ability to learn from examples in the prompt (in-context learning) and often dramatically improves results over zero-shot prompting.

Key Concepts

  • Examples: 2-5 demonstrations of input/output pairs
  • Pattern recognition: Model learns the pattern from examples
  • Consistency: Examples help ensure consistent output format
  • In-context learning: Learning from examples within the prompt

Examples

Few-Shot Classification
Sentiment Analysis with Examples
Classify the sentiment as positive, negative, or neutral. Review: "Absolutely love this product! Best purchase ever." Sentiment: positive Review: "It's okay, nothing special but does the job." Sentiment: neutral Review: "Terrible quality, broke after one day." Sentiment: negative Review: "The packaging was nice but delivery was slow." Sentiment:
Three examples teach the model the expected format and classification criteria.
Few-Shot Formatting
Data Extraction Pattern
Extract the name and date from each sentence. Input: "John Smith was born on March 15, 1990." Output: Name: John Smith | Date: March 15, 1990 Input: "The report by Dr. Jane Doe was published December 1, 2023." Output: Name: Dr. Jane Doe | Date: December 1, 2023 Input: "CEO Michael Chen announced the merger on July 4, 2024." Output:
Examples establish the exact output format you want.

Interactive Exercise

📝
Create Few-Shot Examples

Create a few-shot prompt for converting casual text to formal business language.

Write 2-3 examples showing informal → formal conversion, then add a test case for the model to complete.

Pro Tips
  • Choose diverse examples that cover different cases
  • Keep examples consistent in format
  • Quality matters more than quantity - 3 good examples beat 10 poor ones
  • Place the most relevant examples closest to the query

Related Terms