Chain-of-Thought Prompting
Gen AI · Prompt Engineering
Theory
Chain-of-thought prompting asks the model to work through intermediate steps before giving its final answer, for example by adding "work through this step by step, then give the answer on the last line." Because every generated token becomes context for the next one, writing out the steps gives the model room to build the answer gradually instead of guessing it in a single jump.
It helps most on multi-step problems: arithmetic word problems, logic, multi-hop questions and planning. The trade-off is more output tokens, which means more latency and cost. Some models are trained to reason internally before answering, so an explicit instruction matters less with them. In apps, ask for the final answer in a fixed, easy-to-parse place so you can separate it from the reasoning.
Why we use it
Models make more mistakes when they must jump straight to an answer on a multi-step problem. Asking for steps raises accuracy and makes the reasoning visible, so you can spot where it went wrong.
When to use it
Use it for maths, logic, multi-step analysis and planning. Skip it for simple lookups, short classification or high-volume tasks where speed and cost matter more, or when the model already reasons internally.
How it works
- Multi-step question arrives
- Prompt asks for steps first, final answer last
- Model writes step 1 and uses it as context
- Model writes the next step from the previous ones
- Are all the steps done? Yes: Write the final answer on its own line. No: Continue to the next step.
- App reads only the final answer line
Example
Prompt: "A store had 23 apples. They sold 8 and then received a delivery of 15 more. How many apples now? Think step by step."
Model:
"Start: 23
After selling 8: 23 - 8 = 15
After delivery of 15: 15 + 15 = 30
Answer: 30 apples"Key points
- Especially effective for maths, logic and multi-hop questions
- Trades more output tokens (cost and latency) for higher accuracy
- Ask for the final answer in a fixed spot so code can parse it
- Some models reason internally and need no explicit instruction
- Shown reasoning can still contain errors: check the steps, not just the answer