Sub topic 8
Testing a workflow with fixed inputs and a checklist
What you need before this chapter
This chapter assumes you have read the chapters on prompt templates, structured output, and step chaining. You should be comfortable with a template that takes named inputs, a JSON reply that gets validated, and a workflow that runs several steps in order. The code is short Python. If you don't write Python, you can still follow the method and run the checklist by hand.
Why "it looked fine" is not a test
A reusable workflow runs many times. You usually check it once, on the input you had in mind when you wrote it. That check says little about the next run.
Model output varies between runs, even with the same prompt. A prompt tweak that fixes one brief can quietly break another. A model update can change tone or length without any change on your side. If your only evidence is that one good draft, you will not notice these shifts until a customer or an editor does.
Testing a workflow means running it on the same set of inputs every time and scoring the results against the same criteria. Then a change shows up as a difference in scores, not as a hunch.
This chapter covers three parts:
- A fixed test set of representative inputs.
- A checklist that separates rules a program can check from judgments a person must make.
- A routine for comparing runs before and after any change.
Build a fixed test set
A test set is a small, saved collection of inputs for your workflow. "Fixed" means you do not change it casually. If the inputs move, you cannot tell whether a score changed because the workflow changed or because the inputs did.
How many inputs
Start with 8 to 12 cases. That is enough to cover your main situations and small enough to review by hand. Add cases over time, but only when you find a real failure.
What to include
Choose inputs to cover different kinds of situations, not 10 copies of the typical one.
- Typical cases. Two or three ordinary briefs from past work. These confirm the workflow does its basic job.
- Edge cases. A very short brief, a very long one, a brief with a missing field, or one with unusual characters such as accents or emoji.
- Constraint pressure. A brief where the announcement is hard to say in the word limit, or where the natural wording would break a brand rule (for example, a discount announcement when your brand avoids hype).
- Past failures. Every time the workflow produces something bad in real use, save that input. It is a regression case: a test that guards against a bug coming back.
- Sensitive content. A brief that mentions a competitor, a price, a health or legal claim, or a person's name. These show whether your review and compliance rules trigger.
Remove real customer data from test inputs. Replace names, emails, and account details with invented ones, as the privacy chapter describes.
Store the test set as data
Keep each case in a file so it can be versioned alongside the workflow. A JSON list works well.
import json
TEST_CASES = [
{
"id": "typical_spring_sale",
"inputs": {
"brand_name": "Acme Cycles",
"voice": "friendly, plain, no hype",
"channel": "LinkedIn",
"announcement": "our spring service discount",
"audience": "commuter cyclists",
"max_words": 90,
},
},
{
"id": "edge_very_short_announcement",
"inputs": {
"brand_name": "Acme Cycles",
"voice": "friendly, plain, no hype",
"channel": "LinkedIn",
"announcement": "closed Monday",
"audience": "commuter cyclists",
"max_words": 90,
},
},
{
"id": "pressure_hype_bait",
"inputs": {
"brand_name": "Acme Cycles",
"voice": "friendly, plain, no hype",
"channel": "LinkedIn",
"announcement": "biggest sale of the year, 50% off everything",
"audience": "commuter cyclists",
"max_words": 60,
},
},
]
with open("test_cases.json", "w", encoding="utf-8") as f:
json.dump(TEST_CASES, f, indent=2)Give each case a short, descriptive id. You will use it in reports to say which case failed.
Write a checklist with two kinds of checks
A checklist turns "is this good?" into a list of yes/no questions. Split it into two groups, because the two groups need different tools.
Rule checks: a program can decide
Rule checks have an objective answer. Code can run them on every output, every time, for free.
- Is the reply valid JSON with all required fields?
- Is the word count at or under the limit?
- Does it end with exactly one call to action?
- Are banned words absent (for example "revolutionary", "guaranteed")?
- Is a required disclosure or legal line present?
- Are all links well-formed and from an allowed domain?
Judgment checks: a person decides
Judgment checks depend on taste or context. A program cannot reliably settle them.
- Does it sound like our brand?
- Is the claim accurate given the brief?
- Is the opening line interesting, not generic?
- Would we be comfortable publishing it?
Write each judgment check as a question with a clear yes or no answer. "Is the tone good?" is vague, and two reviewers will answer it differently. "Does it avoid exclamation marks and superlatives?" is sharper. Better still, if a judgment check can be rewritten as a rule, move it to the rule group.
A third option is to use a second model call as a grader for judgment checks. Treat that as a screening tool, not a verdict. Graders are inconsistent and tend to favor fluent text. If you use one, spot-check its scores against a human reviewer on a few cases before you trust it.
Automate the rule checks
The code below runs rule checks on one output and returns the list of failures. It builds on the earlier validation function: the draft must already parse before these checks apply.
import re
BANNED_WORDS = {"revolutionary", "guaranteed", "game-changing"}
def check_post(text, max_words):
failures = []
words = text.split()
if len(words) > max_words:
failures.append(f"too long: {len(words)} words, limit {max_words}")
lowered = text.lower()
for banned in sorted(BANNED_WORDS):
if banned in lowered:
failures.append(f"banned word: {banned}")
if "!" in text:
failures.append("contains an exclamation mark")
cta_hits = re.findall(r"\b(book|call|visit|sign up|shop)\b", lowered)
if len(cta_hits) != 1:
failures.append(f"expected 1 call to action, found {len(cta_hits)}")
return failuresThe call-to-action check is a rough heuristic. It counts trigger verbs, so it can miss a call to action phrased another way and can flag a sentence that merely uses the word "visit". A heuristic like this is still useful. Tune it on your past outputs, and treat a failure as a prompt to look, not as proof.
Run the whole test set
Now connect the pieces. The runner loops over every case, calls the workflow, applies the checks, and collects results.
def run_tests(test_cases, generate, check):
"""generate(inputs) -> text; check(text, inputs) -> list of failures."""
results = []
for case in test_cases:
text = generate(case["inputs"])
failures = check(text, case["inputs"])
results.append({
"id": case["id"],
"output": text,
"failures": failures,
"passed": not failures,
})
return results
def summarize(results):
passed = sum(1 for r in results if r["passed"])
print(f"{passed}/{len(results)} cases passed")
for r in results:
if not r["passed"]:
print(f"- {r['id']}: {'; '.join(r['failures'])}")Here generate is your workflow: it fills the template, calls the model, and returns the text. check wraps check_post with the case's own max_words. Because both are passed in, you can test the runner itself with a fake generate that returns fixed strings. That confirms your checks fail when they should, before you trust a green result.
def fake_generate(inputs):
return "Spring service is here! Book today."
def check(text, inputs):
return check_post(text, inputs["max_words"])
summarize(run_tests(TEST_CASES, fake_generate, check))This prints that no case passed, because the fake text contains an exclamation mark. A test that cannot fail is not a test, so always confirm at least once that yours can.
Handle variation between runs
A model can give a different answer each time. One passing run does not prove a case is safe.
- Run each case several times, for example three to five, when you are making a decision such as shipping a new prompt version.
- Track a pass rate per case, not a single pass or fail.
- Lower the model's randomness setting (often called temperature) if your tool offers one. This reduces variation but does not remove it, and it can make output flatter.
- Treat a case that passes 5 of 5 runs differently from one that passes 3 of 5. The second is unreliable even though it sometimes passes.
Compare before and after a change
The main use of a test set is comparison. Before you change a prompt, template, or model, run the tests and save the results. After the change, run them again and compare.
- Run the current version on the full test set. Save the results as your baseline.
- Make one change. Changing several things at once hides which one caused a difference.
- Run the full test set again.
- Compare rule failures per case, then read the outputs for the judgment checks.
- Keep the change only if it fixes what you wanted and breaks nothing that matters.
Watch for these common errors:
- Fixing the test, not the workflow. If you rewrite a failing case until it passes, you hide the problem. Change a case only when it was wrong or unrealistic.
- Overfitting. A prompt tuned until it passes 12 specific cases may do worse on new briefs. Keep a few cases aside that you do not tune against, and check them only at the end.
- Skipping the read. Rule checks pass on text that is technically correct and still dull or off-brand. Always read a sample of outputs.
- Stale test sets. If your campaigns change, add new representative cases and retire ones that no longer match your work.
Decide what a pass means
Set your thresholds before you run the tests, so the result does not tempt you to move the goalposts. A reasonable starting rule:
| Check type | Example threshold |
|---|---|
| Must-pass cases (legal, privacy, disclosure) | 100% of runs pass |
| Rule checks on other cases | At least 90% of runs pass |
| Judgment checks | A reviewer answers yes on at least 8 of 10 sampled outputs |
| Past-failure cases | 100% of runs pass |
These numbers are examples. Choose values that match the cost of an error. A social post that is easy to edit tolerates more risk than an email going to a large list. Where a mistake is costly, rely on the human review checkpoints from the earlier chapter in addition to tests. Tests catch common regressions, and reviewers catch what the tests were never designed to see.
Keep results so you can look back
Save each run's results with the date, the template version, and the model name. A short JSON or CSV file is enough. When quality drops a month from now, you can find the last good run and see what changed. The next chapter covers how to version and document workflows so those records stay useful to your team.
Exercise
Your LinkedIn post workflow passes 10 of your 10 test cases. You then change the prompt to make the tone warmer, rerun, and 9 of 10 pass. The failing case is a brief about a price increase, which breaks the "no hype" rule. A colleague suggests rewriting that test case so it passes. What should you do instead, and why?
Show answer
Keep the test case as it is, because it is a realistic and important input. The failure shows that the warmer prompt weakened the "no hype" rule on price-related briefs. Revise the prompt, for example by restating the constraint or adding a short example of a price announcement in plain tone, then rerun the full set several times. Change a test case only if it was wrong or unrealistic, not to make a result look better.
Exercise
Sort these checks into "rule check" or "judgment check": (a) the post is under 90 words, (b) the opening line is engaging, (c) the required disclosure line appears, (d) the post sounds like our brand. Then say how you could make (d) more testable.
Show answer
(a) and (c) are rule checks, since code can verify them. (b) and (d) are judgment checks. To make (d) more testable, rewrite it as specific yes/no questions, such as "Does it avoid exclamation marks and superlatives?" and "Does it address the reader as 'you'?" Any of those that can be checked by code move into the rule group, and the rest go to a reviewer as clear yes/no questions.