Sub topic 2
Inputs, steps, and outputs: the anatomy of a workflow
This chapter assumes you have written prompts for a generative AI assistant and can read short Python snippets. You do not need to run the code to follow the ideas. The previous chapter helped you pick recurring tasks worth automating. This chapter shows how to take one of those tasks and describe it as inputs, steps, and outputs. Later chapters build on this structure: templates, structured output, chaining, and review.
Why a workflow needs a shape
A good prompt that you retype each week is not yet a workflow. It lives in your head and your chat history. When a colleague runs it, or you run it three months later, the result changes because the inputs, the wording, and the checks are all slightly different.
A workflow fixes this by making three things explicit:
- Inputs are the facts and settings that change from run to run, such as the campaign brief or the send date.
- Steps are the ordered actions that turn inputs into something new. A step may call a model, apply a rule, or ask a person to decide.
- Outputs are the named results each step and the whole workflow produce, in a form that the next step or tool can use.
Once these are written down, you can test the workflow, hand it to someone else, and see exactly where a bad result came from.
The three parts in detail
Inputs
An input is anything the workflow needs that you do not want to hardcode. It helps to sort inputs into three kinds.
| Kind | Changes how often | Examples |
|---|---|---|
| Per-run inputs | Every run | Announcement, campaign brief, week's metrics, target channel |
| Stable settings | Rarely | Brand name, voice description, word limits, banned phrases |
| Reference material | Occasionally | Product facts, past top-performing posts, style examples |
This split matters because each kind is stored and reviewed differently. Per-run inputs are supplied by the person or trigger starting the run. Stable settings are kept in one shared place so that a change to the brand voice reaches every run. Reference material needs an owner who keeps it current, since stale facts produce confident but wrong copy.
For each input, record four things: its name, what it means, whether it is required, and what a valid value looks like. For example, send_date is required, must be a future date in YYYY-MM-DD format, and is used only in the final step. Writing this down is the cheapest way to prevent the most common failure: a run that starts with missing or malformed data and produces a plausible-looking but wrong draft.
Steps
A step takes named inputs and produces one named output. Keep each step small enough that you can describe its job in one sentence. If you need the word "and" twice, split it.
There are four common step types:
- Model steps send a prompt to a generative model. Examples: summarize a brief, draft three subject lines.
- Rule steps apply deterministic code. Examples: check that a subject line is under 60 characters, strip tracking parameters from a URL, format a date.
- Lookup steps fetch data from a system, such as last week's open rate from an analytics tool.
- Human steps pause for a person to approve, edit, or choose. Chapter 7 covers where these belong.
Prefer a rule step over a model step whenever a rule can do the job. Code gives the same answer every time, costs nothing per run, and is easy to test. Use the model for what rules cannot do well: rewording, summarizing, adapting tone.
Outputs
Every step output gets a name, a type, and a destination. The type might be plain text, a list, or a structured object with fields. The destination might be the next step, a review queue, or a publishing tool.
The final output is the deliverable. Decide its form before writing any prompts. "A draft newsletter" is vague. "A JSON object with subject, preview_text, and body, where subject is at most 60 characters" is something a tool can check and a person can review. Chapter 5 covers validation in depth. For now, notice that specifying the output first tells you what the earlier steps must produce.
A worked example: the weekly newsletter
Take a weekly newsletter for a bike shop. Done by hand, the task is: read the week's announcements, pick the main story, write the email, and send it. As a workflow, it becomes the following.
Inputs
brief(per-run, required): the week's announcements as plain text.send_date(per-run, required):YYYY-MM-DD.brand_voice(stable): "friendly, plain, no hype."max_subject_chars(stable): 60.
Steps and outputs
| # | Step | Type | Reads | Produces |
|---|---|---|---|---|
| 1 | Check inputs | Rule | `brief`, `send_date` | validated inputs or an error |
| 2 | Summarize the brief | Model | `brief` | `summary` |
| 3 | Draft the email | Model | `summary`, `brand_voice` | `draft` |
| 4 | Check length and fields | Rule | `draft` | `checked_draft` |
| 5 | Approve or edit | Human | `checked_draft` | `approved_draft` |
The deliverable is approved_draft. Notice that the model appears in only two of five steps. The rule and human steps around it are what make the workflow dependable.
Writing the workflow down as data
A workflow description does not need special software. A plain data structure works, and it keeps the shape visible. The sketch below checks inputs before running any step and fails with a clear message when one is missing.
from datetime import date
INPUT_SPEC = {
"brief": {"required": True, "type": str},
"send_date": {"required": True, "type": str},
}
def validate_inputs(inputs):
for name, spec in INPUT_SPEC.items():
if spec["required"] and name not in inputs:
raise ValueError(f"Missing required input: {name}")
if name in inputs and not isinstance(inputs[name], spec["type"]):
raise ValueError(f"Input {name} must be {spec['type'].__name__}")
try:
parsed = date.fromisoformat(inputs["send_date"])
except ValueError:
raise ValueError("send_date must look like 2026-12-01")
if parsed < date.today():
raise ValueError("send_date is in the past")
return inputsThis is a rule step. It runs in milliseconds and catches errors before you pay for a model call. Later chapters add templates and chaining on top of it.
Edge cases and common errors
Most workflow failures come from the seams between parts, not from the model.
- Hidden inputs. The prompt quietly relies on something the person "just knows," such as the current promotion. If a new teammate cannot run the workflow from the written inputs alone, an input is missing from the list.
- Overloaded steps. One prompt that summarizes, chooses a story, writes copy, and formats HTML is hard to debug. When the result is bad, you cannot tell which job failed. Split it so each output can be inspected.
- Untyped outputs. If step 2 returns free text and step 3 expects a list, the workflow works until the model changes its phrasing. Name the type and check it.
- Inputs that are too long or empty. An empty brief may produce invented content instead of an error. A very long one may be truncated by the model's context limit. Validate length at the start, with a minimum and a maximum.
- Stable settings buried in prompts. If the 60-character limit appears in three prompts, one will get updated and two will not. Store it once and refer to it by name.
- Treating model output as trusted input. Text from one step flows into the next as data. If a step passes along text copied from an outside source, that text can contain instructions or errors. Check it before it reaches a publishing tool.
- Missing failure paths. Decide what happens when a check fails: retry, stop, or send to a person. In the diagram above, a failed length check returns to drafting. Set a retry limit, such as two attempts, then escalate to a human so the loop cannot run forever.
Designing a workflow: a short procedure
Use this order when you describe a new workflow. It works on paper before you write any code.
- Write the deliverable as one sentence, with its format and who receives it.
- List the per-run inputs. Everything else is a stable setting or reference material.
- Work backward from the deliverable: what intermediate outputs does it need?
- Turn each intermediate output into one step, and label the step as model, rule, lookup, or human.
- Replace any model step with a rule step if a rule can do it.
- For every step, write the name of its output and its type.
- Add a failure path for each check.
- Run the workflow by hand on one real example and note where you improvised. Each improvisation is a missing input or step.
How this connects to the rest of the tutorial
The anatomy you defined here has a home for every later technique. Parameterized templates (Chapter 3) turn model steps into reusable prompts that read named inputs. Brand context (Chapter 4) is the stable settings group. Structured output (Chapter 5) gives each output a checkable type. Chaining (Chapter 6) connects outputs to later inputs. Review checkpoints (Chapter 7) are human steps. Testing (Chapter 8) replays fixed inputs through the whole sequence.
Exercise
A teammate runs your newsletter workflow and gets a draft that mentions a sale which ended last month. The brief they supplied did not mention a sale. List two places in the workflow's anatomy where the cause might be, and one change that would prevent it.
Show answer
The first possible cause is reference material: an outdated product or promotion document was used as context in the drafting step, so the model repeated the old sale. The second is a hidden input: the prompt or a past example contains the sale text, and nobody listed it as an input with an owner. A prevention is to move promotion details into a named input with a required value and an owner, and to add a rule step that flags any promotion not present in the current brief. Dating the reference material and reviewing it on a schedule also helps.
Exercise
You are describing a social media workflow. One proposed step reads "Take the product announcement, write a LinkedIn post, shorten it to 280 characters for X, and add three hashtags." Split it into steps, label each as model or rule, and name each output.
Show answer
Step 1, model: write the LinkedIn post from the announcement, producing linkedin_post. Step 2, model: write a short version from linkedin_post, producing short_post. Step 3, rule: check that short_post is at most 280 characters, producing checked_short_post or an error that returns to step 2. Step 4, model: suggest three hashtags from the announcement, producing hashtags. Step 5, rule: confirm there are exactly three hashtags and append them, producing the final posts. Length counting and hashtag counting are rules because code does them exactly. Wording and tone are model work.
Exercise
Why is it better to validate send_date in code before the first model call than to ask the model to notice a bad date?
Show answer
Code gives the same answer every run, costs nothing per call, and stops the workflow before any model spend. A model might accept a malformed or past date and build a plausible draft around it. Failing early with a clear message also tells the user exactly which input to fix.