noteflowai/evalarc · 0.23.6 · 2026-11-30

fix: name the malformed field when a promptfoo result row, its testCase or its gradingResult is not a JSON object

For promptfoo --output files, load_results and evalarc diff now name the malformed field in three cases: a row in results.results is not a JSON object, a row's testCase is a truthy non-object, or a row's gradingResult is a truthy non-object. A validation pass runs in _promptfoo right after the existing results.results list check. It walks the rows in file order and stops at the first failure. It raises ValueError with a message such as "promptfoo output field results.results[0].gradingResult must be an object (got string) (test '<row 0 label>'): the result row cannot be read. Re-export with promptfoo eval --output instead of editing results." Only the gradingResult message includes the test label. Before this change, these inputs raised AttributeError, and evalarc diff printed the raw Python text, for example "evalarc: 'str' object has no attribute 'get'". evalarc diff still prints the message after 'evalarc: ' on stderr and exits 2. Null, false, 0 and empty testCase or gradingResult values still count as absent. cli.py is unchanged. docs/ci-gate.md lists the three checked fields and says which fields are not checked.

Use it

Prerequisites: a checkout of evalarc at commit d3d3f0f installed in the current Python environment (for example with pip install -e .), and a shell in the repository root. The input below is synthetic: it is a hand-edited copy of the recorded promptfoo example, not a real export.

1. Create the malformed sample file:
python - <<'EOF'
import json
with open("examples/results-diff/promptfoo/current.json") as f:
    doc = json.load(f)
doc["results"]["results"][0]["gradingResult"] = "x"
with open("broken.json", "w") as f:
    json.dump(doc, f)
EOF

2. Run the gate against it:
evalarc diff examples/results-diff/promptfoo/current.json broken.json; echo "exit $?"

Expected stderr:
evalarc: promptfoo output field results.results[0].gradingResult must be an object (got string) (test '<row 0 label>'): the result row cannot be read. Re-export with promptfoo eval --output instead of editing results.
Expected last line: exit 2

3. Fix it by re-exporting with promptfoo eval --output. Do not hand-edit results.

Run the acceptance tests: python -m pytest -q tests/test_feature_5c0e7aa7d572.py

Scope

Measured results: the controller ran all checks. I ran nothing. On base commit 480d1ab, the new acceptance test file failed: 5 failed and 1 passed, each failure with the AttributeError described above. On candidate commit d3d3f0f, all of the following exited 0: the new acceptance tests, the full pytest suite, ruff check, ruff format --check, scripts/build_site.py and scripts/check_site.cjs. check_site.cjs ran the existing showcase browser regression checks at 1440, 390 and 320 px widths. Those checks cover other site pages, not this change. This is a CLI and library change with no UI, so no visual review of this feature was done or needed. Passing tests show the tested shapes behave as specified. They do not prove correct handling of every malformed export. Scope limits: only the result row, its testCase and its gradingResult are type-checked. Wrong types in componentResults, provider, vars, response, assertions and stats are not checked. Inspect and JUnit loading, format detection and cli.py are unchanged. The message does not say which input file failed. Tests use synthetic edits of the recorded promptfoo example, not new real promptfoo exports. Nobody checked whether evalarc diff --output writes files before loading fails. docs/ci-gate.zh-CN.md was not updated.

Upgrade and rollback

No data or schema migration is needed. The planning review read the promptfoo loader, including the row loops and format detection. On that reading, all three rejected shapes already raised AttributeError on every reachable path, so a file that loaded before should load the same way now. The full existing test suite passed unchanged on the candidate commit. Neither check covers new real exports. Files that already failed still exit 2, but now the message names the field. A file with several defects may report a different defect first, because the new checks run before the existing promptIdx and duplicate-testIdx checks. Those existing messages keep their wording. To roll back, reinstall the previous evalarc release. No stored artifacts change.

Source commit: 5cd20a51a8c04e1e89c3973a784e881f505e7173