Skip to main content

1. Introduction

Chain-of-Thought prompting is a prompting technique used to improve performance on tasks that require multiple reasoning steps. Instead of treating a problem as a single question, the task is structured so that the model can work through intermediate reasoning before producing the final result. It is especially useful for tasks involving:
  • Mathematics
  • Logic
  • Multi-step calculations
  • Programming problems
  • Planning
  • Complex decision-making
The two main ideas are:

2. Few-Shot Prompting

Definition

Few-shot prompting provides the model with a small number of examples before giving it the actual task. The examples demonstrate:
  • What the task looks like
  • How the input should be interpreted
  • What type of output is expected
  • What reasoning pattern or solution approach is useful

Basic Example

The model uses the examples to understand the task.

3. Few-Shot Prompting for More Complex Tasks

Few-shot examples can demonstrate how to solve a category of problems.
The examples guide the model toward the expected problem-solving pattern.

4. Step-by-Step Reasoning

Definition

Some problems require multiple steps before reaching a final answer. For these tasks, a useful prompt can ask the model to:
  1. Identify the important information.
  2. Break the problem into smaller parts.
  3. Perform the required operations.
  4. Check the result.
  5. Return the final answer.

Example

The calculation is:
Final answer:

5. Combining Few-Shot and Step-by-Step Reasoning

Chain-of-Thought prompting often combines examples with a structured reasoning approach.

Example Prompt

The example demonstrates the structure and approach expected for the new problem.

6. Zero-Shot vs Few-Shot Chain-of-Thought

Zero-Shot

The model receives instructions but no examples.
The model must determine the reasoning pattern from the instruction.

Few-Shot

The model receives examples before the actual problem.
Few-shot prompting provides an example of the expected reasoning pattern.

7. General Chain-of-Thought Prompt Template

A reusable template is:

8. Few-Shot Chain-of-Thought Template


9. When to Use Chain-of-Thought Prompting

It is useful when the task involves:

Multi-Step Problems

Mathematical Problems

Programming Problems

Data Analysis

Planning


10. Reasoning and Verification

For complex tasks, it is often useful to separate solving from checking.

Example

This creates a simple workflow:

11. Best Practices

1. Use Clear Examples

Few-shot examples should be:
  • Relevant to the actual task
  • Correct
  • Consistent
  • Simple enough to demonstrate the pattern

2. Use Similar Examples

If the actual task is mathematical, use mathematical examples. If the actual task is code generation, use code examples. Poorly matched examples can confuse the model.

3. Ask for Verification

For important tasks, add verification criteria.

4. Avoid Unnecessary Complexity

Not every task requires detailed reasoning. Simple tasks often work well with direct prompting.

Simple Task

Complex Task

Use additional reasoning guidance only when the task benefits from it.

12. Chain-of-Thought vs Direct Prompting


13. Important Limitation

A model’s reasoning process is not guaranteed to be correct simply because it produces a step-by-step explanation. A response can still contain:
  • Incorrect assumptions
  • Calculation errors
  • Missing information
  • Logical mistakes
Therefore, for important tasks, use external verification when possible. For example:
  • Use a calculator for important calculations
  • Run generated code
  • Validate JSON with a parser
  • Check results against source data
  • Test software with unit tests

14. Complete Example

Prompt

Expected Solution


15. Key Takeaways

Simple Formula