Topic 1 of 4 · 5 min read
Fixed workflows with LLM steps
Goal: Rewrite a described task as a fixed workflow with named LLM steps and code checks between them.
A workflow is a program you wrote that calls a language model at fixed points; the code decides the order of steps, and the model only fills in each step. Anthropic's "Building effective agents" draws the same line: workflows follow predefined code paths, agents direct their own process.
Check yourself · 1 of 3
In a workflow, what decides the order of the steps?
Why it matters
Most "AI features" in production are workflows. They are easy to test, easy to debug and cheap to run, because the number of model calls is known before the run starts. If a task has the same shape every time, a workflow is usually the right answer, and calling it an agent adds nothing.
How to build one
- Write the task as steps a person could follow. For "triage a support email": read it, classify it, look up the customer, draft a reply, check the reply.
- Mark which steps need language understanding. Classifying and drafting do. Looking up the customer by id does not; that is a plain database call.
- Give each model step one job and a fixed output shape, such as a JSON object with a
categoryfield from a closed list. - Put a code check between steps. Validate the JSON, check the category is in the list, confirm the draft mentions no refund amount above the limit. A failed check retries once or hands off to a person.
- Log each step's input and output. When something breaks, you can see which step did it.
Before and after
Weak: one long prompt says "Handle this support email: work out the problem, check the account, write a reply, and make sure it follows policy."
Fixed workflow:
- Step 1 (model): classify the email into
billing,bug,accountorother. - Check (code): the value is one of the four; otherwise retry once.
- Step 2 (code): fetch the customer's plan and open tickets.
- Step 3 (model): draft a reply using the category, the customer record and a policy snippet for that category.
- Check (code): no amount above the refund limit; the greeting uses the customer's name.
- Step 4 (code): save as a draft for a human to send.
Each step can be tested alone with a handful of saved emails.
What goes wrong
- Brittleness on odd input. An email in two languages that asks three unrelated things does not fit one category. The workflow has no way to decide to split it, so it picks badly or fails the check.
- Hidden decisions. If the model's output decides what code runs next (a
next_stepfield), you have started building an agent without its guard rails. - Too many steps. Every extra model call adds cost, delay and a place for errors. Merge steps that need the same context.
- Checks that never fail. A check that only tests "is it a string" catches nothing.
Examples
Release notes from merged pull requests
A nightly job lists merged pull requests (code), asks a model to write one line per pull request in a fixed style (model), checks each line is under 120 characters and names the pull request number (code), groups lines by label (code), and asks the model once for a two-sentence summary (model). The path never changes, so you can test it with last month's pull requests.
Invoice field extraction
Step 1 asks a model to return supplier, date, total and currency as JSON. A check confirms the date parses and the total is a positive number. If the check fails, the same call is retried once with the error message added. If it fails again, the invoice goes to a person. No step ever decides what to do next; the code does.
Key points
- In a workflow, your code fixes the order of steps and the model only fills in each step.
- Split a task into steps, then give a model call only to the steps that need language understanding.
- A code check between steps, such as a closed list of categories, catches bad output before it spreads.
- Because the number of calls is known up front, a workflow is predictable in cost and easy to test step by step.
- Workflows are brittle when an input does not fit the path you wrote, and they cannot invent a new path.
Common mistakes
- Calling something an agent when its steps never change; it is a workflow and should be tested like one.
- Letting a model output choose which code branch runs, without a closed list and a code check.
- Putting all the work in one giant prompt instead of separate steps that can be checked.
- Writing checks that only test the output's type, not its content or limits.
Check yourself · 2 of 3
A support-email workflow classifies each email into billing, bug, account or other. What check belongs right after that step?
Check yourself · 3 of 3
A workflow for extracting invoice fields fails on an invoice that is a photo of a handwritten note. Why is this a typical workflow weakness?
Practice items, not counted towards your mastery.
Start here
- Building effective agents (Anthropic) (opens in a new tab)ArticleFree
Defines workflows versus agents and says to find the simplest solution first; the source of this skill's framing.
- A practical guide to building agents (OpenAI) (opens in a new tab)DocsFree
A second vendor's view on when a use case justifies an agent and how to design the loop.
- Workflows and agents (LangGraph docs) (opens in a new tab)DocsFree
Code-level side-by-side of fixed workflows and agent loops, with runnable examples.