Prompt Engineering Fundamentals / Prompt Optimization

Few-Shot Chain of Thought

Intermediate [3/5]
Demonstration-guided reasoning CoT with examples

Definition

Few-Shot Chain of Thought combines few-shot prompting with step-by-step reasoning. You provide examples that include not just the input and output, but also the complete reasoning process that leads from input to output.

This technique is particularly powerful for complex reasoning tasks where showing the thought process helps the model understand how to approach new problems.

Key Concepts

  • Explicit reasoning: Examples show the full thought process
  • Pattern transfer: Model learns the reasoning pattern from demonstrations
  • Step structure: Each step logically leads to the next
  • Answer derivation: Final answer clearly follows from reasoning

Examples

Math Problem
Reasoning Demonstration
Example 1: Q: A store has 45 apples. They sell 12, then receive 20 more. How many? A: Let's work through this step by step. 1. Start with 45 apples 2. Subtract 12 sold: 45 - 12 = 33 apples 3. Add 20 received: 33 + 20 = 53 apples The store has 53 apples. Example 2: Q: A library has 120 books. 35 are borrowed, 15 returned. How many? A: Let's work through this step by step. 1. Start with 120 books 2. Subtract 35 borrowed: 120 - 35 = 85 books 3. Add 15 returned: 85 + 15 = 100 books The library has 100 books. Now solve: Q: A garage has 80 cars. 25 leave, then 18 arrive. How many?
The examples demonstrate the step-by-step reasoning pattern.

Interactive Exercise

Create a CoT Example

Write a few-shot CoT example for this classification task:

Task: Determine if an email is "spam" or "not spam"

Include reasoning steps that analyze the email.

Pro Tips
  • Make each reasoning step explicit and clear
  • Use consistent structure across all examples
  • Include examples of different difficulty levels
  • Ensure the final answer clearly follows from the steps

Related Terms