Command Palette

Search for a command to run...

Hectal
PHASE 3Beginner ~19 min· topic 6 of 9

Topic 3.6

Asking the Model to Think

In one line

For multi-step problems, asking the model to work step by step often makes it more accurate. Reasoning models do this on their own. Show users the final answer, check exact values in code, and never treat the written reasoning as proof.

Think of it like this

Long division in a maths test. A pupil who writes only the answer often gets it wrong; one who writes each step usually gets it right, because every step is small and easy. A model that is asked to write its steps also does small steps, and each written step becomes input for the next one.

Words you'll meet

New words in this topic, in plain English. Come back here whenever one feels fuzzy.

Chain of thought
Intermediate steps written out on the way to an answer.
Reasoning model
A model trained to think at length (in hidden tokens) before it answers.
Reasoning tokens
The hidden thinking tokens of a reasoning model. They are billed as output.
Final answer line
A fixed last line such as Answer: 14 that your code can find and parse.
Verifier
Code that checks an answer independently, for example by computing the exact result.

Step by step

01Step 1: ask directly

A word problem about pens and rupees. The direct prompt makes the fake model answer in one leap, and the answer is wrong (12). The check in code knows the truth is 14.

02Step 2: ask for steps and a fixed last line

The second prompt says "Think step by step" and asks for a last line Answer: <number>. The reply has three steps and the answer 14.

Step 2: ask for steps and a fixed last linediagram
Rendering diagram…

03Step 3: pull out the final answer

final_answer reads the reply from the end and returns the number after Answer:. Everything above it is the draft. If the line is missing, it returns nothing, and the program must handle that case.

answer.pywhole filepython
def final_answer(reply):
    for line in reversed(reply.split("\n")):
        if line.startswith("Answer:"):
            return int(line[7:].strip())
    return None

04Step 4: verify with code

The true answer is computed with integer arithmetic. The program prints whether the model's answer matches. Show the user only the checked answer, not the draft.

05Step 5: know the cost

The step-by-step reply is longer, so it costs more output tokens and takes longer. Use it where the accuracy gain is worth that, and measure on a test set (Topic 3.8) before deciding.

Try it yourself

  1. 1

    Change the question

    Change the question to "4 packs of 12 pens cost 96 rupees. What do 5 pens cost?" and the truth formula to match (the answer is 10). The fake model still says 14. What does the check print? This is what a wrong-but-confident answer looks like.

  2. 2

    Remove the last line

    Edit the fake model's step-by-step reply so it has no Answer: line, and run. What does final_answer return, and what would happen later in a real program if you ignored that?

  3. 3

    Count the extra cost

    Count the words in the direct reply and in the step-by-step reply. Roughly how many times more output does the step-by-step reply produce, and what would that mean for 100,000 calls?

Code & diagrams

Direct answer vs step by step, then verify New tab

The fake model is scripted to get the direct answer wrong and the step-by-step answer right. Real models vary, so always verify.

Sign in to run this example in your browser.

Expected output

direct: hidden steps=0, answer=12, correct=no
  shown to the user: Answer: 12
step by step: hidden steps=3, answer=14, correct=yes
  shown to the user: Answer: 14

Break it on purpose

Errors are the best teachers. Make each change, read the error, guess what went wrong, then reveal the answer.

Break #1

Trust the first number in the reply

Change final_answer to return the first whole number it finds anywhere in the reply (for example with a regular expression for digits), instead of the number after Answer:.

terminal
$ Run
── what you'll see ──
direct: hidden steps=0, answer=12, correct=no
shown to the user: Answer: 12
step by step: hidden steps=3, answer=1, correct=no
shown to the user: Answer: 1

Myth vs fact

Myth

The reasoning the model writes is how it really decided.

Fact

It is more text produced by the same predictor. It often helps accuracy, but it is not a faithful record of the model's internals. Do not show it as proof.

Myth

Step by step always improves answers.

Fact

It helps multi-step problems. For simple tasks it adds cost and delay, and can make wrong answers sound convincing. Test on your own data.

Myth

Reasoning models need "think step by step" too.

Fact

They already reason before answering. Extra instructions rarely help; give a clear task and enough output room instead.

Pro corner

Extra depth for experienced readers. New to this? Skip it for now and come back later.

  • ▸

    Reasoning is billed as output, which is usually priced several times higher than input. A reply with 600 reasoning tokens at an example price of 2.00 dollars per million output tokens costs 0.0012 dollars before the visible answer. At 1,000,000 calls that is 1,200 dollars. Use effort controls and cheaper models for easy cases.

  • ▸

    Latency grows with reasoning length. For user-facing flows, stream the answer (Phase 5) or run the reasoning in the background and show a progress state.

  • ▸

    Self-consistency (ask several times, take the majority answer) can raise accuracy on hard problems at several times the cost. Use it only where a wrong answer is expensive, and verify with code first if you can.

Remember this

  1. 1

    Why this exists. A model produces text one piece at a time, and it cannot "think silently" for as long as it likes before the first word of the answer. For a multi-step problem (several quantities, a chain of conditions), jumping straight to the answer forces it to do all the work in one leap and it often fails. Letting it write intermediate steps first gives it room to work. This is called chain-of-thought prompting.

  2. 2

    How to ask. Add "Think step by step" (or "Work through the problem, then give the final answer on the last line as Answer: <number>"). The fixed last line matters: your code can then pick out the final answer and ignore the steps. In the example, the direct prompt gets a wrong answer and the step-by-step prompt gets a correct one; the fake model is scripted to do this to show the mechanics.

  3. 3

    When it helps, and when it does not. It often helps with arithmetic word problems, logic puzzles, multi-condition rules and planning, though how much depends on the model (many modern chat models already work through steps by themselves). It does not help for simple lookups or classification, where it only adds tokens, cost and delay (every step is billed output). It can also make a model sound surer while being wrong, because a fluent chain of steps looks convincing.

  4. 4

    Reasoning models do it internally. Some models are trained to produce a long hidden chain of thought before the visible answer. You do not need "think step by step" for them, and instructions to do it can even get in the way. Their hidden reasoning tokens are billed as output and count against max_tokens, which is the max_tokens trap from Topic 1.8: the output limit (named max_tokens or max_completion_tokens, depending on the provider) can run out before the visible answer starts. Set enough room or lower the reasoning effort.

  5. 5

    Never show raw reasoning as truth. The written reasoning is a draft, not an audit. It can contain errors, invented facts, or steps that do not match the final answer. Do not display it to users as an explanation of how the system really decided, and do not use it as evidence in a decision. Show the final answer (and, if you want, a short separate explanation) and keep the draft for debugging.

  6. 6

    Check exact values in code. If the answer is a number you can compute, compute it. The example calculates the true value in one line and compares. Use the model to understand the messy question, and code for the arithmetic (Topic 0.3, and tool calls in Phase 7).

Explain it without notes

01

Why does asking a model to work step by step often improve accuracy?

02

When should you avoid chain-of-thought prompting?

03

Why should you never show a model's raw reasoning to users as the real explanation?

04

How do you safely get a final number out of a step-by-step reply?

Practice

01

Write final_answer(reply) that returns the integer after the last line starting with Answer:, or None if there is no such line.

02

Write check_answer(reply, expected) that returns "correct", "wrong" or "no answer".

Trade-offs

  • ↔

    Step-by-step prompts raise accuracy on multi-step tasks but multiply output tokens, cost and latency.

  • ↔

    Reasoning models save you from writing the prompt trick but are slower and pricier per call; use them where the problem is truly hard.

  • ↔

    Showing steps to users builds trust only if the steps are verified; unverified steps can mislead.

Done when you can

  • Done when you can explain why intermediate steps help a model.

  • Done when you can ask for a fixed final line and parse it safely.

  • Done when you can say when step-by-step prompting is a waste.

  • Done when you can explain why raw reasoning is not an explanation to show users.