Skip to main content
Handbook/Amplify/Chapter 67 · AI Workflows

Chaining the Steps

Share

Share this page

Pass it to someone who needs it.

Key takeaway: Chain small steps, not one giant prompt

Some AI tasks are not one task. They are several: read this input, decide what it means, then write the result. Cram all three into one giant prompt and the model turns unreliable and impossible to debug, because you cannot see which part it got wrong. This chapter gets you breaking multi-step AI work into small, checkable steps.

7.4.1Many steps beat one mega-prompt

A workflow chains small model calls, each doing one clear job. One call reads the input, the next decides what it means, a third writes the result. Because every step is small and focused, each one is reliable, and when something breaks you can see exactly which step did it.

A single mega-prompt is one opaque box: it either works or it fails, and a failure tells you nothing about where. A workflow is a line of small boxes you can open and inspect between. That visibility is the whole point.

7.4.2Know when one call is enough

Not every task needs a workflow. The agent you gave your product answers most things in one call, and you reach for a workflow only when a task genuinely has stages or a branch.

One call is enoughYou need a workflow
One clear job: classify, summarize, extractSeveral stages: read, then decide, then write
The output is one shape you check at onceA step's result changes what happens next
Redoing it is cheap if it is wrongA bad early step must be caught before the rest

Do not wrap a one-call task in a workflow. The extra steps only add cost and more places to fail, for nothing.

7.4.3Orchestrate the steps

Orchestration is sequencing the steps, branching on their results, and retrying one that fails. You do not wire this by hand for anything real. A workflow tool like LangGraph, and others like it, runs the chain for you: it calls each step in order, follows the branch, and retries a step that failed.

You do not memorize the shape, your agent writes it. Here is what a three-step chain looks like, one small model call per step, a check between each:

def handle_ticket(email): facts = extract(email) # step 1: read check(facts, "request") # stop if none found route = classify(facts) # step 2: decide check(route, CATEGORIES) # stop if invented reply = draft(facts, route) # step 3: write check(reply, max_len=800) # stop if it rambled return reply
Each step runs, then a check gates it: a passing result feeds the next step, a failing one retries or stops.

The tool also handles the retries and shows you each run. A flaky step recovers on its own, and you see exactly where a run stopped. A workflow often needs to remember what earlier steps produced, and carrying that along is state, another main thing the tool manages for you.

7.4.4Check between the steps

The checks are the point. Validate each step's output before you hand it to the next, so one bad step does not poison the rest. Treat every step's result like input from outside your code: never trust it blindly.

Watch out: an unchecked bad step does not just fail itself. It quietly corrupts every step after it, and the final answer comes out confident and wrong.

A check can be plain: the field exists, the category is one you allow, the text is not empty and not too long. This is the same input-checking that keeps any feature reliable, applied between AI steps instead of only at the front door. Some workflows go further and pause for a person to approve or correct a step before continuing, a human-in-the-loop step.

This prompt turns your task into a checked workflow:

Ready prompt
Act as a senior AI engineer. Take my multi-step AI task below and turn it into a workflow: small steps, each one model call doing a single job. Sequence them in order. Between every step, add a check that validates the output before the next step runs, so one bad step cannot poison the rest. Add a retry on any step that can fail for transient reasons. Tell me whether a plain script or a workflow tool like LangGraph fits my case, and why. Then show me how to run and inspect one step at a time. My multi-step AI task:

Do this now: take one AI feature that reads, decides, then writes inside a single prompt, paste this, and split it into three checked steps.

Mahmoud Zalt

Mahmoud Zalt

Software engineer, 16+ yrs · built Sistava.com in 3 months, idea to production, using these methods

Resources
Contribute
Donate

Support my work

A small tip keeps the free work coming.

© 2026 Mahmoud Zalt. Free to read, not to republish.
Copyright & license