Stop 12 · Prompt EngineeringTopics · 8/10

Prompt Chaining

Part of the AI Engineer Roadmap

In short

One giant prompt that researches, outlines, writes and checks usually does all four badly. Split the job into small prompts that pass results along, and each step gets easier to get right and to debug.

Breaking a complex task into a sequence of smaller prompts, feeding one's output into the next — often more reliable than one giant prompt trying to do everything at once.

The blob dabbawala hands a tiffin box to the next blob in a relay line, with a bicycle nearby.

Think of it like this

The dabbawala relay

No single dabbawala carries your tiffin from home to office. One collects it, another sorts it at the station, a third rides it to the right building. Each does one simple job well. Prompt chaining hands the output of one prompt to the next the same way.

Watch it happen

Turning a lecture transcript into study notes

Transcript
Extract
Outline
Write
Review

1/5Input: a 40-minute lecture transcript, messy and full of 'umm'.

The big ideas

What you need to know

One job per prompt

Small prompts are easier to write, test and improve than one prompt doing everything.

Inspect in between

You can log, check or let a human edit the output of any step before passing it on.

Code can sit between steps

Validate JSON, call an API or filter results between prompts. Not every step needs an LLM.

Trade-off: latency

More steps mean more calls, so more time and cost. Run independent steps in parallel when you can.

See it in code

Walk through the code

python
1def make_notes(transcript: str) -> str:2    terms = ask_llm(f"List the key terms and definitions in this lecture:\n<t>{transcript}</t>")3 4    outline = ask_llm(f"Group these terms into an outline with 3 to 5 headings:\n{terms}")5 6    notes = ask_llm(f"Write short study notes for each heading.\nOutline:\n{outline}\nTerms:\n{terms}")7 8    review = ask_llm(f"List any term from <terms> missing in <notes>, or reply OK.\n"9                     f"<terms>{terms}</terms>\n<notes>{notes}</notes>")10    if review.strip() != "OK":11        notes += "\n\nCheck: " + review12    return notes

1/3Step 1 extracts only the facts, nothing else.

Four small prompts in a row. ask_llm is your own helper that calls any model and returns text.

Save yourself the pain

Common mistakes

Oops

Chaining ten steps for a task one good prompt handles.

Do this instead

Chain only when a single prompt is unreliable. Every step adds delay and cost.

Oops

Passing raw, unchecked output from one step to the next.

Do this instead

Validate in between, especially JSON. A bad early step quietly ruins everything after it.

Your mission

Chain three prompts by hand

~30 min

Quick check

What's a key advantage of prompt chaining over one big prompt?

Go deeper

  1. 1Break a complex task into 2-3 chained prompts and compare quality vs. a single mega-prompt.
  2. 2Learn to design clear input/output contracts between chained steps.
  3. 3Identify when chaining adds unnecessary latency/cost vs. when it genuinely improves quality.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge