Step-by-step Prompting & Reasoning

Generative AI · Lesson 8 of 28 6 min read Updated

Ask a model a tricky question in one go and it may jump straight to a wrong answer. Ask it to work through the problem in steps, or split a big job into smaller prompts, and the quality often improves a lot. Humans work the same way: we solve a long sum line by line, and we write an outline before an essay.

In this lesson you will learn three related techniques: asking for step-by-step working, prompt chaining (splitting a task into a sequence of prompts), and getting the best from reasoning models. You will also learn why you should check any calculation the model makes.

Asking for the working

Remember that a model writes one token at a time. If the very first tokens of the answer must be the final result, the model has no room to work anything out. If it writes the steps first, each step becomes context for the next one. That is why prompts like these help on maths, logic and planning tasks:

Text
A shop in Jaipur sells notebooks at ₹45 each, with 10% off on orders of
20 or more. Priya buys 24 notebooks and pays with a ₹1,000 note.
How much change should she get? Show each step, then give the final
answer on its own line starting with "Answer:".

Asking for the final answer on a separate, labelled line is a useful habit: you can read the steps when you want to check them, and a program can find the answer easily.

For older models, adding a phrase such as "think step by step" made a measurable difference. Newer reasoning models already think before answering (see How LLMs Work), so with them you do not need magic phrases. Instead, give a clear goal, the facts and how you will judge a good answer.

Check the arithmetic yourself

Even when the steps look right, a model can slip on a calculation, because it predicts digits as text rather than running a calculator (unless the tool runs code for it). For anything that matters, recompute the numbers. Python is perfect for this:

PythonRun it yourself
price, quantity, discount = 45, 24, 0.10

subtotal = price * quantity
total = subtotal * (1 - discount) if quantity >= 20 else subtotal
change = 1000 - total

print(f"Subtotal: ₹{subtotal}")
print(f"After 10% discount: ₹{total:.2f}")
print(f"Change from ₹1,000: ₹{change:.2f}")
Output
Subtotal: ₹1080
After 10% discount: ₹972.00
Change from ₹1,000: ₹28.00

Dates and times are another classic trap. Here is a train question that many people (and models) get wrong because the journey crosses midnight:

PythonRun it yourself
from datetime import datetime, timedelta

departure = datetime(2026, 11, 14, 21, 40)         # 9:40 pm from Rohtak
distance_km, speed_kmph = 410, 60
travel = timedelta(hours=distance_km / speed_kmph)
arrival = departure + travel

hours, rest = divmod(int(travel.total_seconds()), 3600)
print(f"Travel time: {hours} h {rest // 60} min")
print("Arrival:", arrival.strftime("%d %b %Y, %I:%M %p"))
Output
Travel time: 6 h 50 min
Arrival: 15 Nov 2026, 04:30 AM

If a model told you the train arrives "at 4:30 am on 14 November", this check catches the wrong date immediately.

Prompt chaining: one step per prompt

Some tasks are too big for one prompt: writing a report, analysing feedback from 200 students, planning an event. Prompt chaining splits the job into stages, and the output of one stage becomes input to the next. You stay in control between stages and can fix problems early.

A typical chain for a college magazine article:

  1. Brainstorm: "Suggest 8 angles for an article on our college's solar panels."
  2. Outline: "Using angle 3, write an outline with 5 sections."
  3. Draft: "Write section 1 from this outline, 150 words, for students."
  4. Review: "Act as a strict editor. List problems in this draft: unclear sentences, unsupported claims, missing facts."
  5. Revise: "Rewrite the draft fixing these problems."

A small Python structure keeps a chain organised. Each stage has a template, and {previous} is replaced by the result of the stage before. Here we only print the prompts; in Using AI APIs from Python you will learn to send them to a real model.

PythonRun it yourself
chain = [
    ("outline", "Write a 5-point outline for a 300-word article on {topic}."),
    ("draft", "Write the article from this outline, for {audience}:\n{previous}"),
    ("review", "List up to 5 problems in this draft (unclear, unsupported or missing):\n{previous}"),
]

def show_chain(chain, **facts):
    previous = "<result of the previous step>"
    for number, (name, template) in enumerate(chain, start=1):
        prompt = template.format(previous=previous, **facts)
        print(f"Step {number} ({name}):\n{prompt}\n")
        previous = f"<{name} written by the model>"

show_chain(chain, topic="the new solar panels at our Pune college", audience="first-year students")
Output
Step 1 (outline):
Write a 5-point outline for a 300-word article on the new solar panels at our Pune college.

Step 2 (draft):
Write the article from this outline, for first-year students:
<outline written by the model>

Step 3 (review):
List up to 5 problems in this draft (unclear, unsupported or missing):
<draft written by the model>

Getting the best from reasoning models

Reasoning models are excellent at hard problems, but they work differently from older models:

  • Give the goal and constraints, not a script. Long lists of tiny steps can make answers worse; describe what a great result looks like and let the model plan.
  • Provide all the facts up front, including what has already been tried.
  • Use them where they shine: maths, logic, coding, planning, careful analysis of long documents. For a quick rewrite or a short email, a fast model is enough.
  • Expect waiting and cost. Thinking takes time and tokens; many apps have a "think deeper" option, and APIs offer an effort or thinking-level setting.

Common mistakes

  • Trusting a neat-looking chain of steps. Steps can look logical and still contain a wrong number. Recalculate.
  • Asking for everything in one giant prompt. Big jobs go better as a chain with checks in between.
  • Micromanaging reasoning models. Explain the goal and the facts; let the model plan its approach.
  • Forgetting dates and time zones. Crossing midnight, leap years and IST versus other time zones cause many errors.

Key points

  • Asking for working gives the model room to reason before it commits to an answer.
  • Put the final answer on its own labelled line so it is easy to find and check.
  • Always recompute important numbers and dates, for example with Python.
  • Prompt chaining splits big tasks into stages and lets you check each result.
  • Reasoning models think on their own; give them goals, facts and success criteria rather than step lists.

Exercise

Kabir earns ₹38,000 a month. He saves 15% of his salary, spends ₹12,500 on rent and the rest on other expenses. A model claims he has "₹19,800 for other expenses". Write a short Python check that calculates the real figure and prints whether the model was right.

Show solution
Python
salary = 38_000
savings = salary * 15 / 100
rent = 12_500
other = salary - savings - rent

model_claim = 19_800
print(f"Savings: ₹{savings:,.0f}, rent: ₹{rent:,}, other expenses: ₹{other:,.0f}")
print("Model was right" if other == model_claim else f"Model was wrong by ₹{abs(other - model_claim):,.0f}")
Output
Savings: ₹5,700, rent: ₹12,500, other expenses: ₹19,800
Model was right

Savings are ₹5,700, so ₹19,800 is left for other expenses. The model was right this time, but the only way to know was to check.

Quick Quiz

1. Why does asking for step-by-step working often improve answers?

2. What is prompt chaining?

3. How should you prompt a reasoning model for a hard planning task?

4. A model's working looks neat and logical. Should you still check its numbers?

Learn Generative AI with a mentor

Free lessons get you started. Our AI Training & Workshops training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call