Sub topic 11
Reporting results and triaging failures
This chapter assumes you already have a golden dataset, deterministic checks, a pass-rate gate, and a CI workflow that runs them. It covers what to do when the gate goes red, and how to make the output useful enough that the first person to see it can decide what to do.
What a report must answer
A bare "pass rate 91% is below baseline 94%" tells you the build failed. It doesn't tell you whether to revert the prompt, rerun the job, fix a test case, or ignore it. A useful report answers these questions in order:
- Did the suite pass the gate, and by how much?
- Which cases changed status compared with the baseline?
- Which parts of the dataset are affected (tags such as
adversarial,long_input,json_output)? - For each new failure, what was the input, the output, and the check that failed?
- Is the failure stable, or did it pass on some repeated runs?
If a reviewer can answer these from the pull request page, without opening logs or rerunning anything locally, the report is doing its job.
Record one result per case
Reporting starts with a machine-readable record of every case, not with pytest's console output. Write one JSON line per case, then build every human-readable view (summary, table, artifact) from that file.
Each record should hold:
id: the stable case ID from the dataset.tags: the dataset categories the case belongs to.passed: a boolean.failed_check: the name or message of the first failing check, ornull.output: the model output, truncated to a sane length.modelandprompt_version: what produced the output.
A conftest.py file next to your eval tests can collect these from the parametrized test shown earlier in the tutorial:
import json
from pathlib import Path
import pytest
RESULTS = []
OUT_PATH = Path("evals/out/results.jsonl")
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
if report.when != "call":
return
callspec = getattr(item, "callspec", None)
case = callspec.params.get("case", {}) if callspec else {}
RESULTS.append(
{
"id": case.get("id", item.nodeid),
"tags": case.get("tags", ["untagged"]),
"passed": report.passed,
"failed_check": None if report.passed else str(report.longrepr)[-500:],
}
)
def pytest_sessionfinish(session, exitstatus):
OUT_PATH.parent.mkdir(parents=True, exist_ok=True)
with OUT_PATH.open("w", encoding="utf-8") as f:
for record in RESULTS:
f.write(json.dumps(record) + "\n")The last 500 characters of the failure text usually contain the assertion line and its values. The head is mostly traceback noise. If you also want the model output in the record, have your test helper stash it somewhere the hook can read it, for example with item.user_properties.append(("output", output)).
Build a summary that shows change, not just state
The report that matters on a pull request is the difference from the baseline. A suite with 6% permanent failures will always look bad, and a reviewer learns to ignore it. A suite that says "2 new failures, 1 fixed, 5 known" gets attention.
For this you need the baseline to store more than a number. Add a list of case IDs that are known to fail:
{
"pass_rate": 0.94,
"known_failures": ["adv-007", "long-012", "fmt-031"]
}The following script turns results.jsonl and the baseline file into a Markdown summary. In GitHub Actions, anything written to the file named by GITHUB_STEP_SUMMARY appears on the workflow run page.
import json
import os
import sys
from collections import defaultdict
from pathlib import Path
def load_results(path):
lines = Path(path).read_text(encoding="utf-8").splitlines()
return [json.loads(line) for line in lines if line.strip()]
def build_report(results, baseline):
total = len(results)
passed = sum(1 for r in results if r["passed"])
rate = passed / total
known = set(baseline.get("known_failures", []))
failed = [r for r in results if not r["passed"]]
new_failures = [r for r in failed if r["id"] not in known]
fixed = sorted(known - {r["id"] for r in failed})
by_tag = defaultdict(lambda: [0, 0])
for r in results:
for tag in r.get("tags", ["untagged"]):
by_tag[tag][1] += 1
by_tag[tag][0] += 1 if r["passed"] else 0
lines = [
"## Prompt regression results",
"",
f"Pass rate: **{rate:.1%}** ({passed}/{total}), "
f"baseline {baseline['pass_rate']:.1%}",
f"New failures: {len(new_failures)}. Fixed: {len(fixed)}. "
f"Known failures still failing: {len(failed) - len(new_failures)}.",
"",
"| Tag | Passed | Total |",
"| --- | --- | --- |",
]
for tag in sorted(by_tag):
ok, n = by_tag[tag]
lines.append(f"| {tag} | {ok} | {n} |")
if new_failures:
lines += ["", "### New failures", ""]
for r in new_failures:
detail = (r.get("failed_check") or "").replace("\n", " ")[:200]
lines.append(f"- `{r['id']}`: {detail}")
if fixed:
lines += ["", "### Fixed since baseline", ""]
lines += [f"- `{case_id}`" for case_id in fixed]
return "\n".join(lines) + "\n"
if __name__ == "__main__":
results = load_results("evals/out/results.jsonl")
baseline = json.loads(Path("evals/baseline.json").read_text(encoding="utf-8"))
report = build_report(results, baseline)
target = os.environ.get("GITHUB_STEP_SUMMARY")
if target:
with open(target, "a", encoding="utf-8") as f:
f.write(report)
else:
sys.stdout.write(report)The per-tag table is the part people skip and later wish they hadn't. A 2% overall drop that is concentrated in the adversarial tag is a different problem from a 2% drop spread evenly.
Wire the report and artifacts into CI
The summary needs to be written even when the tests fail, and the raw results need to survive the job. Use if: always() on both steps. Without it, GitHub skips every step after a failing one, and the report disappears exactly when you need it.
- run: pytest evals -q
env:
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
- name: Write summary
if: always()
run: python evals/report.py
- name: Upload raw results
if: always()
uses: actions/upload-artifact@v4
with:
name: eval-results
path: evals/out/
retention-days: 30These steps replace the single pytest step in the workflow from the CI chapter. They go inside the same job.
Triage: decide what kind of failure it is
When a case fails, the cause is not always the prompt change. Treat each new failure as a hypothesis to classify before you fix anything. There are six common causes.
| Category | Typical sign | Action |
|---|---|---|
| Real regression | Fails on every repeat, started with this change | Fix the prompt or code, or revert |
| Flaky case | Passes on some repeats, fails on others | Rerun, widen the tolerance, or loosen the check |
| Bad check | Output looks acceptable to a human | Fix the assertion or rubric |
| Bad case | Expected output is wrong or the input is ambiguous | Fix or retire the case in the dataset |
| Judge error | Judge verdict disagrees with human labels | Revise the judge prompt, then revalidate it |
| Infrastructure | Timeouts, rate limits, 5xx, empty output | Rerun, add retries, check provider status |
The order of the table is also the order of how often each cause shows up in practice once a suite is mature: real regressions are common right after a prompt edit, and bad checks and flaky cases dominate later.
Step 1: rule out infrastructure
Look at the failure message first. A TimeoutError, a 429, an empty string, or a response with a refusal from a content filter is not information about your prompt. Make your test helper raise a distinct exception type for transport errors so the report can separate "the model gave a wrong answer" from "we never got an answer." If these are counted as ordinary failures, a provider outage looks like a catastrophic regression.
Step 2: rerun to measure stability
Rerun the failing cases only, with the same model and parameters, several times. Five repeats is enough to separate the three situations:
- 0 of 5 pass: a stable failure.
- 5 of 5 pass: a transient failure, likely infrastructure or one unlucky sample.
- 1 to 4 of 5 pass: a flaky case. The prompt is borderline for this input.
A flaky result is still information. If the same case was 5 of 5 before the change and is 3 of 5 now, the change made the model less reliable on that input, even though no single run proves it.
Step 3: read the output, not the assertion
Open the actual output for a stable failure and compare it with what you would accept by hand. Two outcomes are common:
- The output is wrong. Confirm that the failing check describes the real problem, then work on the prompt.
- The output is fine and the check is too strict. For example, a
must_containphrase was "refund policy" and the model now writes "refund terms." Decide whether the phrase is a real requirement. If it isn't, relax the check. If it is, the model changed behavior and that is a regression.
This is the point where tests are most often weakened by habit. Before you loosen a check, write down in the pull request why the old behavior was not required. A weakened check with no reason attached is a hidden regression.
Step 4: compare with the previous run
If you cannot tell whether a failure is new, check whether it fails on the main branch. Run the same case against the base commit, or look at the last scheduled run's artifact. A case that fails on both is a known failure, not something this change introduced. This is why the baseline stores known_failures.
Group failures to find the cause faster
When many cases fail at once, look for the shared factor before reading individual outputs. Group by:
- Tag: all
json_outputcases failing points to a formatting instruction that was lost. - Failed check: the same assertion failing everywhere points to a shared cause, such as a changed system prompt.
- Input length: failures only on long inputs point to a truncated context or token limit.
- Model or prompt version: if you run more than one configuration, compare them.
A handful of grouped cause lines in the PR comment is more useful than 40 individual failure entries. If you need a quick count, collections.Counter over the failed_check field gives you the most common failure messages.
Common mistakes
- Reporting only the aggregate. The overall rate hides category-level collapses. Always show by-tag counts.
- Treating every red build as a prompt bug. Classify first. Infrastructure and flaky failures trained into "just rerun it" habits will cause a real regression to be rerun away, too.
- Rerunning until green. If a case passes on the third attempt, that is a flaky case to record, not a pass to forget. Keep the attempt count in the result record.
- Not saving outputs. Without the raw output you cannot tell a bad check from a bad answer, and rerunning will give a different sample anyway.
- Silent baseline edits. Updating
baseline.jsonto make the build pass, with no explanation, removes the safety net. The next chapter covers how to do this deliberately. - Unbounded log output. Printing full outputs for every case makes the log unreadable. Truncate in the console and keep full text in the artifact.
Exercise
A pull request changes a system prompt. CI fails with pass rate 90.0% against a baseline of 94.0% and a tolerance of 2%. The by-tag table shows that all 8 failures are in the json_output tag, and each failing message says JSONDecodeError. Rerunning those 8 cases five times each gives 0 of 5 passes for every one. What category of failure is this most likely, and what do you check next?
Show answer
It is most likely a real regression, not an infrastructure or flaky failure, because the failures are stable across reruns and concentrated in one tag with one error type. Next, open the raw output of a few failing cases. Check whether the model now wraps the JSON in prose or a Markdown code fence, or whether the prompt edit removed or weakened the instruction to return only JSON. Fix the prompt (or revert the edit). Don't relax the JSON check, because downstream code needs parseable output.
Exercise
A case that has always passed now fails in one CI run. The failure text is 429 Too Many Requests. Rerunning the job passes. How should the report and your test helper treat this, and why?
Show answer
It is an infrastructure failure, not a model failure. The test helper should raise a distinct error type for transport problems (or retry with backoff), and the report should list those cases separately from content failures. Counting them as ordinary failures would lower the pass rate for reasons unrelated to the prompt and could trigger the regression gate falsely.