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

  1. Multi-step question arrives
  2. Prompt asks for steps first, final answer last
  3. Model writes step 1 and uses it as context
  4. Model writes the next step from the previous ones
  5. Are all the steps done? Yes: Write the final answer on its own line. No: Continue to the next step.
  6. 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

Gen AI topics

Foundations of Generative AI

Prompt Engineering

Retrieval & Embeddings

Customizing Model Behavior

AI Agents & Tool Use

Multimodal & Applied AI

Ethics, Cost & Careers

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Generative AI for the Data Stack

LLMs, prompt engineering, RAG, embeddings, agents and the tools shaping modern AI products — explained practically. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Section {{ sec.num }}

{{ sec.label }}

Gen AI  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

💡

{{ current.tldr }}

Explained

{{ para }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
See It In Action
{{ current.example }}
Key Takeaways — click to check off
{{ pt.mark }} {{ pt.text }}

Share this topic