Chain-of-thought prompting guides an AI through a complex task as a sequence of smaller, logical steps instead of requesting a single final answer. A useful prompt supplies the problem context, asks what to check first, and continues through decisions or evidence needed for the next step. This approach aims for clearer, more accurate responses while leaving the developer in control of the result. section 9.5.1 section 9.0
Build a chain-of-thought prompt around three working parts:
- Sequential reasoning: divide the problem into manageable steps that can be addressed in order. section 9.5.1
- Contextual awareness: provide enough task-specific information for the model to interpret each step and its constraints. section 9.5.1
- Iterative refinement: evaluate an answer, add new information or corrections, and ask for the next revision. section 9.5.1 section 9.7
Diagnose a Python application in Docker
Rather than asking why an application crashes, lead the investigation: ask whether the container is running with `docker ps -a`; if stopped, ask how to inspect errors with `docker logs`; if running, ask how to enter it and inspect application logs; then verify the Python version, dependencies, and Dockerfile configuration. Each answer determines the next check, turning a vague failure into a testable debugging path. section 9.5.1
Stage an implementation decision
For a caching system, request the cache interface first, an in-memory implementation next, and eviction policies last. For an authentication design, ask for reasoning about JWT versus session-based authentication before requesting code. Staging work this way makes it easier to inspect and revise individual decisions. section 9.6.1 section 9.6.1
Figure 9.6 A chain-of-thought prompt gets the model to reason out a problem like a human would. You break down the problem and experiment with answers until you get the results you desire.
The diagram reinforces the workflow: break down the problem, experiment with answers, and refine until the result is useful. section 9.5.1

















