An LLM feature can pass a test ten times and fail the eleventh with everything unchanged. That breaks the foundational QA assumption — same input, same output — and every practice built on it. The replacement discipline is statistical: run N times, define a pass threshold, and know the difference between variance and flakiness.
Tier: Core · Workflow area: Testing AI systems — foundations
This playbook establishes run-N-times pass criteria for an LLM-backed feature, introduces pass^k for agent workflows, and gives you the vocabulary that changes triage forever: variance is the system under test; flakiness is the test.
pytest-repeat, a simple loop script, or Promptfoo's repeat: option.Measure before you set thresholds — establish the variance baseline. Run each test case 20 times against the unchanged system:
pytest tests/test_summarizer.py --count=20 -q
Or in Promptfoo:
tests:
- vars: { ticket: "refund not processed after 14 days..." }
assert:
- type: llm-rubric
value: "mentions refund delay AND names the 14-day period"
# run with: promptfoo eval --repeat 20
case_refund : 19/20 pass (0.95)
case_multi_issue: 14/20 pass (0.70)
case_empty_body : 20/20 pass (1.00)
That 0.70 case is not a broken test — it is a measurement of the system's real reliability on that input. You cannot set a sane threshold without this baseline; teams that skip it pick 100% and then delete the suite in frustration.
Classify every sub-100% case: variance or flakiness? For each failing run, read the transcript and ask what failed:
Fix flakiness ruthlessly (loosen string matches into semantic checks, add retries on 429s) — otherwise your statistics measure your harness, not your model. Only after the harness is clean do the pass rates mean anything.
Set per-case thresholds by consequence, not by wish.
Prompt to your assistant:
Here are 12 test cases for our support-ticket summarizer with measured
20-run pass rates and a description of each case's user-facing risk.
Propose a pass threshold per case using these bands:
- Safety/compliance behaviors (refuses to promise refunds): 100% — any
failure blocks release.
- Core correctness on clean inputs: ≥ 95%.
- Hard/ambiguous inputs: ≥ 80%, tracked for improvement.
Flag any case whose measured rate is already below the proposed bar.
The bands are the point: one uniform threshold is always wrong in both directions — too lax for safety, unachievably strict for genuinely hard inputs.
For multi-step agents, compute pass^k — this is where intuitions die. An agent that is 95% reliable per step, across 10 sequential steps, completes the journey at 0.95^10 ≈ 60%. Per-step pass rates that sound excellent compound into coin flips:
steps: 1 3 5 10
p=0.99 0.99 0.97 0.95 0.90
p=0.95 0.95 0.86 0.77 0.60
p=0.90 0.90 0.73 0.59 0.35
Test agents both per-step (where did it break?) and end-to-end run-N-times (what does the user experience?), and set the release criterion on the end-to-end number — because that is the one users live with.
Wire the criteria into CI with statistical gates. The suite runs each case N times (N=5–10 in CI for cost; 20+ nightly) and fails when a case drops below its threshold — not when any single run fails. Report pass rates, not pass/fail, so trends are visible: a case drifting 0.95 → 0.85 over three weeks is a regression a binary gate never shows.
Re-baseline on every intentional change. New model version, edited prompt, changed temperature: rerun the 20× baseline before comparing anything. Comparing new-model runs against old-model thresholds without re-baselining is the most common self-inflicted "regression" in AI QA.
Variance is a property of the system under test — measure it, threshold it, report it. Flakiness is a property of your test harness — eliminate it. Every confusing AI-testing debate your team will have collapses once those two words stop being used interchangeably.
Put the three-line pass^k table from step 4 in front of product owners before agent-feature planning, not after. "Per-step 95% means six users in ten finish the journey" reshapes scope conversations faster than any QA argument you will ever make.