Sub topic 8
Testing a Workflow with Fixed Inputs and a Checklist
This chapter assumes you can write a parameterized prompt template, have seen a structured output validator, and know how a workflow chains steps. You will build a small test set and a checklist so you can tell whether a change to your workflow made it better or worse.
Why "it looked fine" is not a test
A workflow runs many times. If you judge it by reading one output after each edit, you will miss regressions. A regression is a case that used to work and now fails. A prompt tweak that improves the newsletter intro may quietly break the social post.
Model output also varies between runs. One good result does not show that the workflow is reliable. You need the same inputs, the same checks, and a record you can compare over time.
Build a fixed test set
A test set is a small collection of inputs you reuse every time you change the workflow. Aim for 5 to 10 cases. Choose them to cover the range of real use:
- A typical case, such as a standard product announcement.
- A short or thin input, such as a brief with two lines of detail.
- A long or messy input, such as pasted notes with repeated points.
- An edge case, such as a brief with a missing audience or a price that must not be changed.
- A case that has failed before. Add each real failure you find, so it never returns unnoticed.
Store the cases in a file under version control, so the whole team tests against the same inputs.
Write a checklist with pass or fail items
A checklist turns "is this good?" into questions with clear answers. Split it into two kinds of checks.
| Kind | Example | How to check |
|---|---|---|
| Rule check | Subject is 60 characters or fewer | Code |
| Rule check | Output has exactly one call to action | Code or a person |
| Judgment check | Tone matches the brand voice | A person |
| Judgment check | Every claim appears in the brief | A person |
Write each item so two reviewers would give the same answer. "Sounds engaging" is vague. "Opens with the customer benefit, not the company name" is checkable.
Automate the rule checks
Rule checks are cheap to run on every output, so put them in code. The runner below uses the same call_model idea as the chaining chapter: any function that takes a prompt and returns text.
import json
def check_email(raw):
"""Return a list of failed checks for one email draft."""
failures = []
try:
data = json.loads(raw)
except json.JSONDecodeError:
return ["output is not valid JSON"]
for key in ("subject", "preview_text", "body"):
if not isinstance(data.get(key), str):
failures.append(f"missing field: {key}")
if failures:
return failures
if len(data["subject"]) > 60:
failures.append("subject longer than 60 characters")
if data["body"].lower().count("book now") != 1:
failures.append("body must contain exactly one 'book now' call to action")
return failures
def run_tests(cases, build_prompt, call_model):
results = {}
for name, inputs in cases.items():
raw = call_model(build_prompt(inputs))
results[name] = check_email(raw)
passed = sum(1 for f in results.values() if not f)
print(f"{passed}/{len(results)} cases passed")
for name, failures in results.items():
for failure in failures:
print(f" {name}: {failure}")
return resultsRun the test set before and after every change. Compare the two reports to see exactly what moved.
Add human judgment for the rest
Code cannot judge tone or truthfulness. For those items, a person scores each output against the judgment checks. Keep it light: score pass or fail, and note one reason for each fail. Do this for the whole test set when you change a prompt, and for a sample after small edits.
The testing loop
Common mistakes
- Changing the test set to fit the workflow. If a case fails, fix the workflow. Only change a case when the requirement itself changed.
- Testing once. Run each case two or three times for important workflows, since outputs vary.
- Testing only happy paths. Failures come from thin, messy, and unusual inputs.
- Changing several things at once. You then cannot tell which edit caused a result.
Exercise
You edit the prompt to make subject lines punchier. The typical case passes, but you did not run the others. Give two reasons this is risky and name what you should do instead.
Show answer
The edit may break other cases, such as thin or messy briefs, and one passing run does not show reliability because outputs vary. Run the full fixed test set, including the edge cases, run the automated rule checks and the human judgment checks, and compare the results with the previous run before keeping the change.