CoachnestCoachnest
Sign InGet Started
Back to course

Prompt Engineering Mastery: From Fundamentals to Production

…
—
Contents
1

What Is Prompt Engineering?

ReadingFree
2

How Large Language Models Actually Work

ReadingFree
3

Tokens, Context Windows, Temperature & Sampling

Reading11m
4

The Anatomy of a Great Prompt

Reading13m
5

Module 1 Knowledge Check

Quiz8m
6

Zero-Shot, One-Shot & Few-Shot Prompting

Reading12m
7

Role & Persona Prompting

Reading9m
8

Instruction Clarity, Delimiters & Decomposition

Reading11m
9

Controlling the Output Format

Reading10m
10

Module 2 Knowledge Check

Quiz8m

Chain-of-Thought Prompting

Reading12m
12

Self-Consistency & Tree-of-Thought

Reading11m
13

ReAct — Reasoning + Acting with Tools

Reading12m
14

Structured Output with JSON Schemas

Reading11m
15

Module 3 Knowledge Check

Quiz8m
16

Retrieval-Augmented Generation (RAG)

Reading13m
17

Prompt Templates, Variables & Chaining

Reading11m
18

Tool / Function Calling Patterns

Reading12m
19

Project — Build a Customer Support Assistant

Reading14m
20

Module 4 Knowledge Check

Quiz8m
21

Evaluating Prompt Quality

Reading12m
22

Prompt Injection & Security

Reading12m
23

Reducing Hallucinations

Reading10m
24

Cost, Latency & Optimization

Reading10m
25

Final Assessment — Prompt Engineering Mastery

Quiz15m
←→navigate lessons
Chapter 3 of 5·Module 3 · Advanced Reasoning & Structured Output
Lesson 11 of 25Reading12 min

Chain-of-Thought Prompting

#Chain-of-Thought (CoT) Prompting¶

The technique that unlocked LLM reasoning on math, logic, and multi-step problems.

The Problem¶

Ask directly:

text
3 lines
1Q: A shop had 23 apples. It sold 7, then received a delivery
2   of 12. How many apples now? Answer with a number only.
3A: 28

Wrong. The model "blurted" a plausible-looking number because answering immediately gives it no room to compute.

The Fix: Ask It to Think Step by Step¶

text
3 lines
1Q: A shop had 23 apples. It sold 7, then received a delivery
2   of 12. How many apples now?
3Let's think step by step.

Start: 23. After selling 7: 23 − 7 = 16. After delivery of 12: 16 + 12 = 28. Answer: 28.

By generating intermediate tokens, the model uses computation as scratch space. Reasoning happens in the output, so it must be allowed to produce it before the final answer.

Zero-Shot CoT¶

Just append a trigger phrase:

  • "Let's think step by step."
  • "Work through this carefully before answering."
  • "First, reason about the problem. Then give the final answer."

Few-Shot CoT¶

Even stronger: show worked examples with reasoning, then the new question.

text
5 lines
1Q: Roger has 5 balls. He buys 2 cans of 3 balls each. How many?
2A: 5 + 2×3 = 5 + 6 = 11. The answer is 11.
3
4Q: A cafe had 20 muffins, sold 13, baked 9 more. How many?
5A:

Separate Reasoning From the Final Answer¶

So your code can parse the answer cleanly:

text
2 lines
1Think step by step inside <reasoning></reasoning> tags,
2then give ONLY the final numeric answer inside <answer></answer> tags.

Then extract the <answer> content and discard the reasoning.

When To Use / Avoid¶

Use CoTSkip CoT
Math, logic, planning, multi-hop questionsSimple lookups / classification
"Why" and "how" analytical tasksLatency-critical, trivial tasks

CoT costs extra tokens and latency — it's a tool for hard problems, not every prompt.

Key insight: Reasoning models think because the tokens of thought are part of generation. Never force a hard problem to answer in zero tokens of reasoning.

Previous

Module 2 Knowledge Check

Next

Self-Consistency & Tree-of-Thought

Use ← → arrow keys to navigate between lessons