Skip to content
FORGENO ADS GAMESUnlock all $8

Prompt Engineering & AI Automation · Unit 6 of 8

Unit 6: Prompt chains and workflows

Splitting work into testable steps, deciding what the model does and what code does, adding gates and human review, and handling errors that compound.

Opens the first lesson of this unit in Prompt Engineering & AI Automation. Every lesson is open from the start.

Lesson 1: One giant prompt or a chain?

Goal: Explain prompt chaining and its advantages over one large prompt.

A single prompt that must read an email, classify it, look up the policy, decide on a refund and draft a reply is doing five jobs at once. When it fails, you cannot tell which job failed. Prompt chaining splits the work into steps, where each step is one focused prompt or a piece of ordinary code, and the output of one step becomes the input of the next.

One big promptA chain
One pass or fail for everythingEach step can be tested on its own
One failure spoils the whole resultA failed step can be retried alone
The same model does everythingA cheap model for easy steps, a stronger one for hard steps, code where code is better
No natural place for checksValidation and human review fit between steps

Worked example: a support email chain

  1. Extract: pull the order number, product and problem into JSON.
  2. Classify: label it damaged_item, late_delivery, question or other.
  3. Look up (code, not a model): fetch the order and the matching policy section.
  4. Draft: write a reply using only the policy text.
  5. Check: validate the output, and send any refund promise to a person before it is sent.

Five small, testable steps instead of one opaque one.

Chains are what most real "AI automations" are, whether they are built in code or in a no-code automation tool. The skill is deciding where to cut the task into steps, so that each step has one clear job and an output you can check.

Prompt chain
A workflow of several steps in which each step's output feeds the next, mixing model prompts and ordinary code.
Step
One stage of a chain with a single job and a checkable output.

Remember: One job per step, each with an output you can check.

Lesson 2: Designing the steps

Goal: Write step contracts and split work between the model and code.

Design a chain the way you would plan a relay race: each runner has one leg, and the baton handover is agreed in advance. For each step, write down its contract: what it receives, what it returns (ideally JSON with a schema), and what counts as failure.

Use code for what code does better. Dates, arithmetic, database lookups, sending emails, sorting and filtering should be ordinary code: exact, fast, free and predictable. Use the model for language: reading messy text, judging tone, classifying, summarizing and drafting.

JobModel or code?
Find the order number in a messy emailModel
Check that the order number existsCode (database lookup)
Work out the date 30 days after an invoiceCode
Decide whether a message is a complaintModel
Add up line itemsCode
Draft a polite replyModel
Send the replyCode, after approval

Worked example: a contract for one step

Step 2: classify
  Receives: {"text": string}   (the cleaned email body)
  Returns:  {"category": "damaged_item" | "late_delivery" | "question" | "other",
             "confidence": "high" | "low"}
  Fails if: the output is not valid JSON, or category is not an allowed value
  On failure: retry once, then send the email to the human queue

Anyone can now test this step, replace its prompt or swap its model, as long as the contract still holds.

Step contract
What a step receives, what it returns and what counts as failure.
Deterministic code
Ordinary code that gives the same result for the same input every time.

Remember: Model for language, code for facts, dates, math and actions. Write a contract for every step.

Lesson 3: Gates, routes and human review

Goal: Place validation, business rules, routing and human approval between steps.

Between steps, add gates: checks that decide whether work continues, goes back or goes to a person. Gates are where reliability comes from.

  • Validation gate: does the output parse and match the schema? If not, retry or stop.
  • Business-rule gate: is the refund under the automatic limit? Does the order belong to this customer?
  • Routing: different categories take different paths: complaints to the senior team, questions to the FAQ step.
  • Human review: a person approves anything with real consequences before it happens: money, legal statements, messages to important customers, and anything the model marked low confidence.

Hands-on lab in the room: Workflow chain builder. Build a chain for incoming support emails and run it on six test emails. See what slips through when a gate is missing. The steps are simulated with simple rules, so you can watch exactly what each one does.

Worked example: routing by risk

  1. A chain drafts replies to customer emails.
  2. Questions with a matching FAQ answer are sent after a spot check of 1 in 10.
  3. Complaints, and any reply that mentions money, wait for a person to approve.
  4. Anything the classifier marks low confidence goes straight to the human queue.

Human attention goes where mistakes are costly, and routine work keeps flowing.

Gate
A check between steps that decides whether work continues, is retried or goes to a person.
Human in the loop
A design in which a person reviews or approves certain outputs before they take effect.
Routing
Sending items down different paths depending on their category or risk.

Remember: Validate every handover. Route by risk. A person approves anything with real consequences.

Lesson 4: When chains fail

Goal: Calculate compounding error and design steps that fail safely.

Errors multiply along a chain. If each of three steps is right 95% of the time and their errors are independent, the whole chain is right only about 0.95 × 0.95 × 0.95 ≈ 86% of the time. With five such steps it drops to about 77%. That is why each step must be measured, and why gates matter.

Worked example: finding the weak link

  1. A chain has three steps that are right 98%, 90% and 99% of the time.
  2. Whole chain: 0.98 × 0.90 × 0.99 ≈ 0.87, so about 87% of items get through correctly.
  3. Improving the 90% step to 98% gives 0.98 × 0.98 × 0.99 ≈ 0.95.
  4. Improving the 99% step to 100% would barely change anything.

Measure every step and work on the weakest one first.

  • Fail loudly: a step that cannot do its job should stop and report, not pass on an empty or made-up value.
  • Retry with limits: one or two retries, then escalate. Never loop forever.
  • Never act twice: if a step that sends an email is retried, check whether the email was already sent first.
  • Timeouts: a step that hangs should give up after a set time and report it.
  • Log every run: inputs, outputs, the version of each prompt, and where it stopped. Without logs you cannot debug.
Compounding error
The way small error rates in each step multiply into a larger error rate for the whole chain.
Idempotent
Safe to repeat: doing it twice has the same effect as doing it once.

Remember: Multiply the step accuracies. Fix the weakest step first. Fail loudly, retry a little, never act twice.

Practise it in Prompt Engineering & AI Automation

Each lesson ends with three questions that check you can use the idea, not just recognise it. Wrong answers explain why and come back in Review. The unit ends with a 6-question quiz; pass it with 80% or more to master the unit. Hands-on lab: Workflow chain builder.

Every lesson is free: no ads, no lives and no paywall.