Skip to content

fix(graders): validate judge verdicts and honor token budgets - #738

Closed
shfunc wants to merge 2 commits into
mainfrom
ilya/fix-judge-verdict-handling
Closed

shfunc wants to merge 2 commits into
mainfrom
ilya/fix-judge-verdict-handling

Conversation

@shfunc

@shfunc shfunc commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

An empty or malformed LLM judge response can currently become UNMET, which awards credit when grading a negative criterion. Explicit max_tokens values are also silently discarded, leaving every judgment at 1024 tokens.

Forward the configured budget, reject truncated responses, and require a structured MET/UNMET verdict with a non-empty explanation. Malformed responses get one format-repair attempt before raising a grading error.

Extracted from #731 into three files: the shared judge, its regression tests, and its API docs. This PR targets main; #731's operational-data template depends on it for its 16K judge budget.

Validation: 95 grader tests pass on both Python 3.11 and 3.12; Ruff lint/format and grader type checks pass. Tests use mocked gateway responses.

The six blank-explanation regression cases fail before this follow-up and pass after it. A temporary checkout combining this PR with #726's existing Claude compatibility fix passes the full SDK suites on Python 3.11 and 3.12 (1,640 passed each, six skipped, 27 integration cases deselected), both full type checks, and 80.51% coverage. The Claude fix remains in #726.


Note

Medium Risk
Grading semantics change: malformed or truncated judge output now fails the grade rather than defaulting to UNMET, which fixes negative-criterion bugs but may surface errors in tasks that previously limped through.

Overview
LLMJudgeGrader now accepts a max_tokens argument (default 1024), forwards it to each per-criterion gateway call, rejects non-positive values, and surfaces the budget on the parent SubScore metadata. Responses that hit the token limit (finish_reason == "length") raise a RuntimeError instead of being scored.

Verdict handling is stricter: the judge must return JSON with MET/UNMET and a non-empty explanation. The old tolerant fallback (e.g. scanning for "MET" in free text, which could silently score UNMET and wrongly reward negative criteria) is removed; invalid output gets one format-repair follow-up, then ValueError. Criterion info now includes attempts, and the system prompt requires explanations.

Docs in graders.mdx describe max_tokens and the new error behavior. Regression tests cover repair flow, truncation, invalid payloads, and budget wiring.

Reviewed by Cursor Bugbot for commit d4c5643. Bugbot is set up for automated code reviews on this repo. Configure here.

CI sequencing: the current main branch still has the Anthropic 2.1 message-constructor issue fixed in #726. This PR's lint-ty job reports the same five errors in the unchanged Claude adapter. Merge #726, update this branch from main, then merge this grader fix before #731. The grader-specific tests and type checks pass.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T12:41:02.577528Z ffd244a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

shfunc added a commit that referenced this pull request Oct 22, 2026
Move the shared judge implementation, regression tests and API docs to #738. The operational-data template retains its configured judge budget and depends on that fix before release.

@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: ffd244a96d

ℹ️ 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".

Comment thread hud/graders/judge.py
Comment on lines +180 to +181
or data.get("criterion_status") not in ("MET", "UNMET")
or not isinstance(data.get("explanation"), str)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject empty verdict explanations

When the judge returns {"criterion_status":"MET","explanation":""} (or whitespace only), this condition accepts it and awards the score even though the new public contract requires a verdict with an explanation. Validate that the explanation remains non-empty after stripping whitespace so an unsupported judgment receives the documented repair attempt and ultimately fails if unrepaired.

AGENTS.md reference: AGENTS.md:L71-L75

Useful? React with 👍 / 👎.

@jdchawla29

Copy link
Copy Markdown
Collaborator

Closing in favor of #719, which fixes the NOT MET misread while keeping the judge's prose-verdict contract.

@jdchawla29 jdchawla29 closed this Oct 27, 2026
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.

2 participants