Prompt chaining: breaking big tasks into steps
Learn to split a big task into a chain of small prompts, where each answer feeds the next. You'll plan a Brew & Bean weekend promotion by hand, then wire the same chain into a short Python script.
A single giant prompt ("research, plan, write and format a whole marketing campaign") often gives a shallow result: some parts are good, some are skipped and you can't tell which step went wrong. Prompt chaining means splitting the job into several small prompts, where the output of one becomes the input of the next.
In this tutorial you will plan a weekend promotion for the Brew & Bean coffee shop with a four-step chain, first by pasting between chat windows, then as a Python script. You need a free chat tool (ChatGPT, Gemini, Claude or Copilot). Python 3 is needed only for the last part, and the script runs without any AI account. You should have read *Be specific* and *Getting structured output*.
Why chain?
One big prompt vs a chain
| Question | One big prompt | Chain of small prompts |
|---|---|---|
| Quality of each part | Model rushes through all parts | Each step gets full attention |
| Finding a mistake | Hard: you see only the final result | Easy: check each step's output |
| Fixing a mistake | Rerun everything | Rerun one step |
| Control | Little | Edit the output between steps |
| Effort | One prompt | More prompts and more copying |
Chaining is not always better. For a simple task, one clear prompt is faster. Chain when the task has distinct stages (gather, decide, write, check), when the output of one stage needs your judgement, or when one prompt becomes so long that parts get ignored.
The task and the chain
The owner wants a weekend promotion that gets more people ordering ahead on the website. The chain has four steps. Each has one job and a clear output.
The four-step chain
- 1Ideas: generate 6 promotion ideas that fit the shop (pickup only, 8 am to 10 pm, the real menu).
- 2Choose: you pick one idea (a human step), and the model turns it into a short plan with an offer, timing and a way to measure it.
- 3Write: turn the plan into one WhatsApp message and one Instagram caption.
- 4Check: review the messages against the plan and the facts, and list any problems.
Step 1: generate ideas
Brew & Bean is a small pickup-only coffee shop in Indiranagar, Bengaluru, open 8 am to 10 pm. Menu: espresso ₹120, cappuccino ₹180, cold brew ₹220, filter coffee ₹80, masala chai ₹90, butter croissant ₹150, banana bread ₹130, veg grilled sandwich ₹160. Customers order ahead on our website.
Give me 6 ideas for a weekend promotion that gets more people to order ahead on the website. Each idea: a short name and one sentence. Ideas must be cheap for a small shop to run and must not need seating or delivery. Number them 1 to 6 and write nothing else.What to expect: You should get six numbered one-line ideas, such as a combo (chai + banana bread) or an early-morning offer. Reject ideas that need things the shop doesn't have, such as a seating area or delivery.
Step 2: you choose, the model plans
This is a human checkpoint. Read the ideas and pick one. This is where chains beat one giant prompt: your judgement goes in the middle. Copy your chosen idea into the next prompt.
Here is the chosen promotion idea for Brew & Bean (pickup only, 8 am to 10 pm, orders on our website):
---
[paste the idea you chose]
---
Turn it into a plan with these headings: Offer (exact items and prices in ₹), When it runs (days and hours), How customers claim it, How we'll measure success (one number we can read from our order records), Risks. Use only items from the menu below. Keep it under 150 words.
Menu: espresso ₹120, cappuccino ₹180, cold brew ₹220, filter coffee ₹80, masala chai ₹90, butter croissant ₹150, banana bread ₹130, veg grilled sandwich ₹160.What to expect: Check the arithmetic of any combo price yourself, and that the measure of success is something the shop can actually count (for example, orders placed between 8 am and 10 am on Saturday and Sunday).
Pass only what the next step needs
Don't paste the whole chat into each step. Pass the specific output the next step needs (here, the plan) plus the facts it must respect. Shorter inputs mean fewer chances for the model to latch onto the wrong detail, and the step can be rerun on its own.
Step 3: write the messages
Using only the plan below, write two things:
1. A WhatsApp message to regular customers: under 40 words, one emoji at most, ends with "Order ahead: [website link]".
2. An Instagram caption: under 60 words, with 3 hashtags.
Use only the facts in the plan. Do not invent offers, prices, times or discounts.
Plan:
---
[paste the plan from step 2]
---What to expect: Count the words. Check every price and time against the plan.
Step 4: check
Models review text better when this is a separate job. Asking the same prompt to write and check its own work rarely finds much; a fresh prompt with a reviewer's role and the plan to check against does better.
You are a careful editor. Compare the messages to the plan and list every problem you find: any price, time, item or offer in the messages that is not in the plan, any word limit exceeded, and anything misleading. If there are no problems, say "No problems found" and explain what you checked.
Plan:
---
[plan]
---
Messages:
---
[messages from step 3]
---What to expect: A good reply is a short list of specific problems ("The WhatsApp message says 10 am but the plan says 9 am") or an explanation of what was checked. If it finds problems, rerun step 3 with the list added, not the whole chain.
Put the chain in a script
Once a chain works by hand, you can automate it. The script below runs the same four steps. It does not need an AI account: the function ask is a stand-in that returns a fixed reply so you can see how data flows between steps. To use a real model, replace the body of ask with an API call (see *Your first LLM API call (free Gemini API)* in the AI Engineering track). Save it as chain.py and run python chain.py.
FACTS = (
"Brew & Bean is a pickup-only coffee shop in Indiranagar, Bengaluru, "
"open 8 am to 10 pm. Menu: espresso 120, cappuccino 180, cold brew 220, "
"filter coffee 80, masala chai 90, croissant 150, banana bread 130, "
"veg sandwich 160 (rupees)."
)
def ask(prompt):
"""Stand-in for a real model call. Replace this body with an API call."""
print("--- PROMPT ---")
print(prompt)
print()
return "[model reply goes here]"
def ideas():
return ask(
f"{FACTS}\n\nGive 6 ideas for a weekend promotion that gets more people "
"to order ahead on the website. One short sentence each, numbered."
)
def plan(idea):
return ask(
f"{FACTS}\n\nTurn this promotion idea into a plan under 150 words with "
f"headings: Offer, When, How to claim, How to measure.\n\nIdea: {idea}"
)
def write(plan_text):
return ask(
"Using only the plan below, write a WhatsApp message under 40 words "
f"and an Instagram caption under 60 words.\n\nPlan:\n{plan_text}"
)
def check(plan_text, messages):
return ask(
"List every price, time or offer in the messages that is not in the "
f"plan.\n\nPlan:\n{plan_text}\n\nMessages:\n{messages}"
)
idea_list = ideas()
print("Ideas:", idea_list)
chosen = input("Paste the idea you choose: ").strip() # human checkpoint
plan_text = plan(chosen)
messages = write(plan_text)
report = check(plan_text, messages)
print("Review:", report)Each function does one step and returns text. The output of one function is passed as an argument to the next, which is all a chain is. The input() line is the human checkpoint.
--- PROMPT ---
Brew & Bean is a pickup-only coffee shop in Indiranagar, Bengaluru, open 8 am to 10 pm. Menu: espresso 120, cappuccino 180, cold brew 220, filter coffee 80, masala chai 90, croissant 150, banana bread 130, veg sandwich 160 (rupees).
Give 6 ideas for a weekend promotion that gets more people to order ahead on the website. One short sentence each, numbered.
Ideas: [model reply goes here]
Paste the idea you choose: Design tips for good chains
Before you build a chain
- Each step has one job and one clearly defined output.
- The output format of one step matches what the next step expects (see *Getting structured output*).
- Facts the model must respect (menu, prices, hours) are repeated in each step that needs them; models don't remember between separate chats.
- You can read the output of each step on its own and judge it.
- There is a human checkpoint before anything is sent to customers or changes data.
- You know which step to rerun when the result is bad.
Errors travel down the chain
A wrong or invented detail in step 2 will be repeated confidently in steps 3 and 4. A checking step helps but is not a guarantee, because the reviewer is also a model. Verify prices, dates and claims yourself before anything is published.
How this comes up in interviews
In AI engineering interviews you may be asked how to build a reliable multi-stage LLM feature, such as summarising a support ticket, classifying it and drafting a reply. A strong answer describes separate steps with clear inputs and outputs, validation between steps, logging of each step's result and a human or rule-based check before any action. Chains with fixed steps are different from agents that decide their own steps; that difference is covered in *AI agents: tools, loops and planning* in the AI Engineering track.
Try it: Chain a task of your own
Choose a task with stages: planning a college fest event, writing a project report, or preparing for an interview at a named company. Design a chain of 3-4 steps on paper: for each step write its input, its job and its output. Run it by hand in a free chat tool, with a human checkpoint after step 1 or 2. Then compare the result with doing the whole task in one prompt.
Key takeaways
- Prompt chaining splits a big task into small prompts where each output feeds the next.
- Chains make mistakes easier to find and fix, and put your judgement in the middle.
- Pass each step only what it needs, and repeat key facts where they are used.
- Use a separate checking step with a clear reference to check against.
- Errors propagate along the chain, so verify facts yourself before publishing.
- Don't chain simple tasks; one clear prompt is faster.
Check yourself
Finishing the quiz marks the lesson as done.
1. What is the main advantage of chaining prompts over using one very long prompt?
2. In the Brew & Bean chain, why is choosing the idea left to a human?
3. Step 3 produces a WhatsApp message with a price that is not in the plan. What is the best next action?
4. In chain.py, what does the output of plan(chosen) do?
5. Which task is best handled with a single prompt, not a chain?
Saved on this device. Create a free account to keep it on every device.
Practise this with Sam
A real mock interview, out loud, with an honest scorecard. Free to start.