Skip to content

chore(evals): grade a judge reply only when its verdict is unambiguous, retry once, and keep the reply - #839

Merged
sumithr merged 12 commits into
mainfrom
fix/issue-796-judge-verdict-parse
Oct 4, 2026
Merged

sumithr merged 12 commits into
mainfrom
fix/issue-796-judge-verdict-parse

Conversation

@sumithr

@sumithr sumithr commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

The Claude judge provider required the verdict to be the reply's last JSON object, so valid judge replies (a verdict followed by notes, prose with braces, a repeated verdict) aborted eval runs. It now finds the reply's one verdict wherever it sits, grades it only when it is unambiguous, retries a reply without a usable verdict exactly once, and keeps the full redacted reply when it still fails. The rule is fail-closed: a doubtful reply is asked again and then errors with the reply kept for diagnosis; it is never graded from a guess.

Related issue

Closes #796

Changes

  • tests/evals/promptfoo/providers/claude_cli.py:
    • Verdict extraction: scans every top-level JSON object; grades only when exactly one verdict (an object with "pass") exists, every pass key in the reply (any spelling, quoting or case) belongs to that verdict, no quoted-key object fails to decode, no decoded object was cut out of a larger structure, no key repeats, no nested pass disagrees with the top-level one, and no stated grade contradicts pass ("Verdict PASS"/"VERDICT: FAIL" on the same line, uppercase, past is/was/of and punctuation; a verdict/passed/result string). Only the rubric's exact format template is exempt. Repeats of the same verdict still grade.
    • One bounded retry for a reply without a usable verdict; token and cost usage cover every call made.
    • On a terminal failure the full reply is written to tests/evals/results/judge-replies/ (gitignored) with secrets (sk-, GitHub tokens, AWS keys, Slack tokens, JWTs, PEM blocks, credential assignments such as password=, client_secret:, Authorization: Bearer) and the home directory (either separator form) redacted before encoding; the console error keeps a redacted 400-character excerpt and names the file.
  • tests/fixtures/judge_replies.json: real judge replies (two passes, one fail, one no-verdict answer) used as fixtures in five shapes each.
  • tests/test_claude_cli_provider.py: graded and refused cases for every rule above, retry and usage accounting, redaction, and the kept-reply file.
  • tests/evals/promptfoo/README.md: the rule in plain words and its trade-off.

Rubrics, thresholds and claude-judge.yaml are unchanged.

Drift from the issue text: the replies that originally failed were never stored in full (only 400-character excerpts survive), so AC1's "real failing replies" are real replies plus the failure shapes built from those excerpts; the new kept-reply file captures the full reply next time. The judge prompt (in the issue's scope) is unchanged: no captured reply shows what it should say differently, and any change would move every grade.

How it was verified

  • tests/test_claude_cli_provider.py: 222 passed; every captured fixture shape grades and equals its json.loads value; origin/main's parser errors on the trailing-object and raw-newline shapes of all three real verdicts.
  • CI on the final head (a9755282): all 28 checks green incl. Windows; mutation gate run 37202525282 green (0 survivors); pre-push full suite 5633 passed at 100% coverage.
  • Real Claude-pair evals through the changed provider on the final head: skill-deciding-approach.yaml 5/5 and skill-implementing-with-tdd.yaml 6/7 (the one fail is a deterministic candidate assertion), 12 judge calls, 0 judge errors, 0 retries, every graded pass matching its stated verdict word. Retry, kept-reply and contradiction behaviour checked through call_api with a stub CLI (full ledger in the proof comment).
  • Review: sumo-qa per-file review and /code-review high on the whole diff, then on every fix delta. After six rounds of heuristics each opened new silent-pass cases, the parser was rewritten fail-closed (your decision); the following rounds closed duplicate keys, variant pass keys, cut-out objects, nested and stated-verdict contradictions.

Not changed, noted for later (accepted residuals, none graded differently from origin/main, which ignores everything but the last object):

  • Stated-verdict wording the check does not read: other words between "verdict" and the grade ("Verdict per the decision table: FAIL", "verdict is therefore FAIL"), a lowercase grade, per-axis grades without the word "verdict", a JSON-escaped separator inside reason, and a boolean result key.
  • Prose or markdown key forms the sweep does not read (HTML entities, *pass*:, pass is false, pass -> false).
  • A score that contradicts pass (promptfoo applies thresholds).
  • False refusals by design: a reply that mentions a pass key outside its verdict, quotes an unclosed JSON fragment, echoes the format template directly before a FAIL verdict, or follows a JSON object with ,, " or : is retried and may error.
  • Windows home paths in doubled-backslash (JSON-escaped), lowercase-drive or Git Bash (/c/Users/...) form are not redacted; a bare Bearer <token> without a key is not redacted; a few labels ("Tokens: 1200") lose their first value word.

Checklist

  • PR title follows Conventional Commits
  • Tests pass locally (pytest) and lint/type checks are green (pre-commit run --all-files, python -m mypy)
  • Added or updated tests covering the change
  • Updated the relevant docs in this same PR
  • No breaking changes (or they are called out above)

…eply without one, and keep it in full

The Claude judge provider required the verdict to be the reply's last JSON
object, so replies that opened with a passing verdict were recorded as
graderError and aborted the run (#796).

- The verdict is now the reply's one top-level object with a "pass" key,
  wherever it sits; objects and prose around it are ignored. Raw control
  characters inside a string decode. Two different verdicts are an error.
- A judge reply with no valid verdict is asked once more. When the second
  has none either, both replies are written in full, redacted, to
  tests/evals/results/judge-replies/ (gitignored) and the error names the
  file next to the 400-character excerpt.
- A valid first reply reaches promptfoo unchanged, after one call.
- Tests run on real judge replies (tests/fixtures/judge_replies.json) in each
  failure shape the recorded excerpts point at.

Rubrics, thresholds and the judge prompt are unchanged.

Closes #796
…ested inside it

A verdict-shaped object that does not decode (truncated, a trailing comma,
unescaped quotes in the reason) is now a "malformed verdict object" error, so
the scan never grades a {"pass": true} nested inside a broken FAIL verdict.
Duplicate verdicts are compared as JSON text, so "pass": 1 never merges with
"pass": true. Kept replies are redacted per string before json.dumps (a
Windows home path is now scrubbed), the kept path names home as ~, the secret
list covers the bare-secret shapes feedback_memory refuses plus github_pat_,
and an error after spent calls carries their tokenUsage and cost.
A failed-decode `{` that opens a quoted key is refused whatever its first
key; the rubric's format template (a <placeholder> first value) and prose
braces are skipped. Verdicts dedupe by equality with the pass type kept,
errors and excerpts are redacted, home is redacted only as a whole path,
a PEM private-key block is redacted, and a failed call's reported usage
is counted.
Replace the first-key guessing for undecodable objects with one rule: every
"pass" key in the reply, other than the rubric's format template, must lie
inside a decoded top-level object, else the reply is a malformed verdict and
is asked again. Undecodable braces without a pass key (a quoted Python dict,
a JS snippet) are skipped.

Dedupe verdicts on a canonical JSON form that merges 1 and 1.0 but keeps
types apart at every depth. Redact CLI output before the excerpt cut and
before repr, and redact home before punctuation but not inside another path.
An object that opens with a quoted key but does not decode now spans to its
closing brace, counted outside quoted strings, or to the end of the reply. A
verdict or a "pass" key inside that span refuses the reply; a "pass" key in
prose outside every such span is ignored, and the format template is matched
tolerantly by its own span. The home redaction keeps `/Users/al.smith` intact.
Replace the failed-brace range scanner with a fail-closed rule. A judge
reply is graded only when its decoded verdict objects are all the same
verdict, none is the value of a quoted key, every "pass" key sits inside
that verdict or the rubric's exact format template, and no quoted-key
object fails to decode. Anything else is retried once and then kept as
an error, never graded from a guess.
An unescaped quote lets raw_decode accept a short prefix of a broken
object, after which a nested verdict decoded as if it were top level.
Any decoded object followed by a comma, quote, colon, closing brace or
bracket was cut out of a larger structure, so the reply is refused.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54f51bf217

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sumithr

sumithr commented Oct 4, 2026

Copy link
Copy Markdown
Owner Author

Merge-readiness evidence, head a9755282

CI: all 28 checks green on a97552829f0e819a53c712bf79e645de40f2c441, including the Windows pytest legs (fixed in 08deb84d: the tests now build paths portably).

Mutation gate: triggered (tests/**). Run 37202525282: every module at or above baseline, 0 survivors, strict gate passed.

Review threads: 0 open. The review bot's P1 ("Final verdict is FAIL" not read) and P2 (credential assignments not redacted in kept replies) were fixed in e0eb76a5 and tightened in a9755282 (a stated grade is read only on its own line, as an uppercase PASS/FAIL; credential values are redacted for bold, env-style, quoted and Authorization forms); both threads resolved.

Per-file review (sumo-qa reviewing_before_merge, full content vs origin/main): no fail-open regression versus origin/main's provider; all captured fixture shapes grade.

/code-review (high): whole diff, then every fix delta. After six rounds of heuristics each opened new silent-pass cases, the parser was rewritten fail-closed (your decision); later rounds closed duplicate keys, variant pass keys, cut-out objects, and nested or stated-verdict contradictions.

Behavioural verification (step 4.7):

# behaviour observed met
1 real judge replies grade normally through the changed provider final head a9755282, real Claude pair (haiku candidate, claude-opus-5-5 judge) on skill-deciding-approach.yaml (5/5) and skill-implementing-with-tdd.yaml (6/7; the one fail is a deterministic candidate assertion, the judge passed it at 0.85): 12 judge calls, 0 judge errors, 0 retries, 0 kept-reply files; every graded pass matches its "Verdict" word. An earlier head (54f51bf2) also ran three configs, 13 judge calls, 0 errors yes
2 a reply with no verdict is retried exactly once, then errors provider call_api with a stub claude: two calls, then judge reply has no verdict object ... (asked twice; both replies kept at ~/.../judge-reply-<id>.json) yes
3 the terminal error keeps the full redacted reply and a concise excerpt kept file holds both replies whole, planted token and home path redacted; console excerpt names the file yes
4 conflicting / contradicting / duplicate-key replies are errors each made 2 calls and errored; origin/main's provider graded all three silently yes
5 valid replies byte-compatible at the provider boundary the three real fixture verdicts return identical dicts from this head and origin/main yes
6 no rubric, threshold or candidate output loosened only the provider, its README, its test and the fixture changed; no yaml yes

Acceptance criteria (#796): 2-7 met. AC1 ("real failing replies captured as redacted fixtures") is met only as real replies plus the failure shapes reconstructed from the surviving 400-character excerpts: the original failing replies were never stored in full. The new kept-reply file captures the full reply next time.

@sumithr
sumithr merged commit 237ea59 into main Oct 4, 2026
29 checks passed
@sumithr
sumithr deleted the fix/issue-796-judge-verdict-parse branch October 4, 2026 12:47
sumithr added a commit that referenced this pull request Oct 4, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.74.0](v0.73.1...v0.74.0)
(2026-10-04)


### Features

* **installer:** save the MCP tool profile once for every launch path
([#836](#836))
([b9215a8](b9215a8))
* **release:** ship SBOM, build provenance and digests, and pin every
action to a commit SHA
([#838](#838))
([df310e6](df310e6))


### Miscellaneous Chores

* **evals:** grade a judge reply only when its verdict is unambiguous,
retry once, and keep the reply
([#839](#839))
([237ea59](237ea59))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: the Claude judge provider rejects verdicts it cannot parse as JSON, aborting eval runs whose judge text says pass

1 participant