Velamuvi AIAcademy

Lesson 6 of 15 · Core Techniques

Step-by-Step Reasoning

Why step-by-step reasoning improves AI answers on maths, logic and planning: chain-of-thought prompting, reasoning models and separating reasoning from answers.

  • 7 min read
  • Beginner
  • Reviewed
In this lesson you will learn
  • What chain-of-thought prompting is and why it works
  • How to ask for reasoning, and how to keep it separate from the answer
  • How reasoning models change the picture
  • When step-by-step reasoning is worth the extra time and cost

A famous puzzle

A bat and a ball cost 110 cents in total. The bat costs 100 cents more than the ball. How much does the ball cost?

Most people's instant answer is 10 cents. Check it in code:

Try it yourselfPython
# A bat and a ball cost 110 cents in total.
# The bat costs 100 cents more than the ball. How much is the ball?

# The quick answer most people jump to:
ball = 10
bat = ball + 100
print(f"Quick answer: ball {ball}, bat {bat}, total {ball + bat}  <- not 110!")

# Step by step: check every possible price for the ball
for ball in range(0, 111):
    bat = ball + 100
    if ball + bat == 110:
        print(f"Checked answer: ball {ball}, bat {bat}, total {ball + bat}")

The quick answer feels right but fails the check. Working it through gives 5 cents. Language models can fall into exactly the same trap, and the fix is the same: work it through before answering.

Chain-of-thought prompting

Prompt

A bat and a ball cost 110 cents in total. The bat costs 100 cents more than the ball. How much does the ball cost? Reply with the answer only.

Example response

10 cents

The intuitive but wrong answer. (Today's strong models usually get this famous puzzle right, but the same failure appears on less familiar problems.)

Why writing it out helps

Remember how a model works: it produces one token at a time, and each token gets a fixed amount of computation. A hard answer squeezed into one token has very little "thinking" behind it.

When the model writes out steps, every step becomes part of the text, and later tokens can build on earlier ones. The written reasoning acts as scratch paper. It is the same reason you do long division on paper instead of in your head.

How to ask for reasoning

From simplest to most controlled:

  1. A nudge: "Think it through step by step before answering."
  2. Named steps: "First list the facts given. Then write the equation. Then solve it. Then check the answer against the facts."
  3. Separate the reasoning from the answer, so a person or program can easily find the result:
Think through the problem inside <thinking> tags.
Then give only the final answer inside <answer> tags.

Separating them matters when the output feeds into something else: a program can extract the text between the answer tags and ignore the working.

Reasoning models

With reasoning models, adding "think step by step" usually adds little, because they already do it. Two tips work better:

  • Give high-level guidance, not a rigid recipe. "Think carefully about edge cases and check your answer" often beats a prescribed list of steps, because the model's own approach may be better than yours.
  • Choose the effort level. Many apps and APIs let you set a thinking level. Use more for hard problems and less for easy ones, to save time and money.

When to use it, and when not to

Use step-by-step reasoning forSkip it for
Maths and word problemsSimple facts and definitions
Logic puzzles and planningRewriting or translating text
Comparing options with trade-offsShort creative writing
Finding a bug in codeQuick classification at large volume

Reasoning costs more tokens and more time. For thousands of simple requests, that cost adds up for no benefit.

Common mistakes

Practice exercise

The model was asked to think inside thinking tags and put only the final answer inside answer tags. Pull out just the answer, as a program would.

Your solutionPython
response = """<thinking>
Call the ball b. The bat is b + 100.
Together: b + (b + 100) = 110, so 2b = 10 and b = 5.
</thinking>
<answer>5 cents</answer>"""

# Print only the text between <answer> and </answer>
Knowledge check

Why does asking a model to write out its steps often improve its answer on a maths problem?

Summary

  • Chain-of-thought prompting asks the model to reason step by step before answering.
  • It works because written steps act as scratch paper that later tokens build on.
  • Ask for reasoning in thinking tags and the result in answer tags so it is easy to extract.
  • Reasoning models think automatically; give them high-level guidance and choose the effort level.
  • Use it for maths, logic, planning and debugging; skip it for simple, high-volume tasks.

Next: using delimiters and structure to keep prompts unambiguous.

Finished reading? Tick it off to track your progress.