fix: reject an Inspect sample whose scores field is not an object with a named error instead of crashing
Inspect logs now fail with a named error when a sample's scores field is a non-empty list, a non-empty string, a non-zero number or true. Before this commit, load_results raised AttributeError, and evalarc diff exited 2 with only "evalarc: 'list' object has no attribute 'items'" on stderr. The controller's run on base 5060961 recorded that output, and the sample was not named. Now load_results raises ValueError. The message names the sample id (in Python repr form, for example 'address-change'), the sample's position and the JSON type it received (array, string, number or boolean), and says to re-export the log with inspect log dump. The check covers .json logs and .eval archives, and it also runs for samples that have an error field. Missing, null or falsy scores still load as no scores, and object scores are read as before. The commit also adds docs/results-diff-inspect-scores.md, which the CHANGELOG entry cites. That page covers the error message form, exit code 2, the absence of a report folder, the recovery steps and the values that still load as no scores. The plan said no documentation page would change. The page was added anyway because the product docs needed the recovery guidance. Controller results: on base 5060961, tests/test_feature_cf3fcccffda5.py gave 8 failed and 2 passed, which reproduces the defect. On candidate 762410959a9b, the feature tests, the full pytest suite, ruff check, ruff format --check, scripts/build_site.py and scripts/check_site.cjs all exited 0.
Use it
Prerequisites: Python 3, a checkout of this repository at commit 762410959a9b, and evalarc installed from that checkout (for example pip install -e .). The commands below build a SYNTHETIC malformed log from the bundled example. It is not a real Inspect export. Run them from the repository root:
python - <<'EOF'
import json
with open("examples/results-diff/inspect/current.json") as f:
doc = json.load(f)
doc["samples"][0]["scores"] = ["C"] # synthetic corruption
with open("current-bad.json", "w") as f:
json.dump(doc, f)
EOF
evalarc diff examples/results-diff/inspect/baseline.json current-bad.json --output review
echo "exit: $?"
Expected result: exit 2, no review folder, and a stderr message of this form: Inspect log sample '<id of the first sample>' at position <position> has scores of type array: expected an object mapping scorer names to scores. A sample whose scores cannot be read would hide its checks from the comparison. Re-export the log from Inspect (inspect log dump) instead of editing it. The id and position come from the log. To recover from a real failure, re-export the log from Inspect instead of editing it by hand. If you run the same command with examples/results-diff/inspect/current.json, it loads as before. See docs/results-diff-inspect-scores.md for details.Scope
Falsy non-object scores ([], "", 0, false) still load silently as no scores. The fix does not validate individual score entries or values. It does not handle a non-string stop_reason. Promptfoo and JUnit loading are unchanged. All test fixtures are synthetic edits of the bundled example logs, not real malformed exports, so the tests do not show how often real logs hit this case. The feature test checks that no report folder exists after exit 2, and the controller's final run of that test passed. The controller's receipts give exit codes for the final run but no pass counts. This change has no UI. The scripts/check_site.cjs browser checks that passed are existing showcase regression checks. They ran at widths of 1440, 390 and 320 px, plus offline variants. They did not review this feature visually. I ran nothing myself. Every result above comes from controller execution.
Upgrade and rollback
Upgrade by installing evalarc at commit 762410959a9b. Logs that loaded before give the same results. The report schema, CLI flags and gate logic are unchanged. Only logs with a truthy non-object scores value behave differently. evalarc diff still exits 2 for them, but stderr now names the sample instead of saying "has no attribute 'items'". Scripts that matched the old stderr text need updating for the new message. Library code that caught AttributeError from load_results needs to catch ValueError instead. To roll back, reinstall the previous version (base 5060961). No data or stored evidence needs migrating.