fix(evals): default unparseable judge scores below pass threshold (#1892)
Some checks failed
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Waiting to run
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Waiting to run
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Waiting to run
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Waiting to run
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Waiting to run
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Waiting to run
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Waiting to run
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Waiting to run
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Waiting to run
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Waiting to run
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Waiting to run
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Waiting to run
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Waiting to run
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Waiting to run
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Waiting to run
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Waiting to run
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Blocked by required conditions
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Blocked by required conditions
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Blocked by required conditions
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Blocked by required conditions
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Blocked by required conditions
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Blocked by required conditions
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Blocked by required conditions
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Blocked by required conditions
Docker / promote-latest (push) Blocked by required conditions
Init E2E / docker-init-e2e (push) Failing after 1m11s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1m9s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1m9s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 5s
Merge Conflicts / merge-conflicts (push) Failing after 6s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 6s
Release Please / release-please (push) Failing after 4s
Security / Dependency audit (pip-audit) (push) Failing after 1m13s
Security / CodeQL (javascript-typescript) (push) Failing after 1m12s
Security / CodeQL (python) (push) Failing after 1m1s
Wrap E2E / docker-wrap-e2e (push) Failing after 5s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 6s
Security / Secret scan (gitleaks) (push) Failing after 21s
CI / commitlint (push) Failing after 12m9s
CI / changes (push) Failing after 12m17s
CI / test (3) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled

## Description

`_parse_judge_response` in `headroom/evals/memory/judge.py` defaulted
the score to `3.0` whenever it couldn't find a parseable `Score:` line
in the judge's raw text. `before_after.py`'s `GroundTruthEvaluator`
treats `judge_score >= 3.0` as "contains ground truth" (`contains_gt =
judge_score >= 3.0`). Because `3.0` is exactly the pass threshold, any
judge response the parser couldn't understand (malformed output, missing
`Score:` line, a refusal, truncated text, etc.) silently counted as a
pass instead of surfacing as a scoring failure, biasing
BFCL/ground-truth eval accuracy upward with no visibility into how often
it happened.

The fix tracks whether a real score was actually parsed out of the
response. If nothing parseable was found, the score now defaults to
`0.0` (a hard fail, below the `>= 3.0` threshold) and a `logger.warning`
is emitted with the raw judge text so the failure is visible instead of
silent.

Refs #1890.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- `headroom/evals/memory/judge.py`: `_parse_judge_response` now tracks
whether a `Score:` line was successfully parsed; on failure it defaults
to `0.0` instead of `3.0` and logs a warning with the raw response text.
- `tests/test_memory_eval.py`: added
`TestJudge.test_parse_judge_response_unparseable_defaults_to_failing_score`,
asserting an unparseable response scores below the `3.0` pass threshold.

## Testing

- [x] Unit tests pass (`uv run pytest tests/test_memory_eval.py -k
judge`)
- [x] Linting passes (`uv run ruff check headroom/evals/memory/judge.py
headroom/evals/runners/before_after.py tests/test_memory_eval.py && uv
run ruff format --check headroom/evals/memory/judge.py
headroom/evals/runners/before_after.py tests/test_memory_eval.py`)
- [ ] Type checking passes (`uv run mypy headroom`) — not run; not part
of this repo's local validation loop for this change
- [x] New tests added for new functionality when applicable
- [x] Manual testing performed

### Test Output

```text
tests\test_memory_eval.py .......                                                                                [ 77%]
tests\test_verbosity_learn.py ..                                                                                 [100%]
9 passed

$ uv run ruff check headroom/evals/memory/judge.py headroom/evals/runners/before_after.py tests/test_memory_eval.py && uv run ruff format --check headroom/evals/memory/judge.py headroom/evals/runners/before_after.py tests/test_memory_eval.py
3 files already formatted
```

## Real Behavior Proof

- Environment: Windows 11, Python (uv-managed venv), no LLM provider
calls needed — `_parse_judge_response` is a pure text-parsing function.
- Exact command / steps: checked out the pre-fix version of
`_parse_judge_response` (default `score = 3.0`) and ran the new
regression test against an unparseable response (`"The model's response
looks reasonable overall."`, no `Score:` line). Confirmed it failed with
`assert 3.0 < 3.0`. Restored the fix and reran — passes, with `score ==
0.0`.
- Observed result: pre-fix, an unparseable judge response scored `3.0`
and would have passed `contains_gt = judge_score >= 3.0` in
`before_after.py`. Post-fix, the same input scores `0.0`, fails the
threshold, and logs a warning naming the raw response text.
- Not tested: the live
`create_openai_judge`/`create_anthropic_judge`/`create_litellm_judge`
call paths (require provider API keys) and the end-to-end
`GroundTruthEvaluator.evaluate` flow in `before_after.py` — only the
pure parsing function and its documented contract with the `>= 3.0`
threshold were exercised.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] I have updated the CHANGELOG.md if applicable

## Additional Notes

- CHANGELOG.md is intentionally left untouched — this repo's release
pipeline generates it from conventional commits.
- No user-facing docs describe the parse-failure default, so no
documentation changes were needed.
- Kept the change minimal and localized to the parsing function; didn't
touch `before_after.py`'s threshold or comments since its `>= 3.0`
semantics for successfully-parsed scores are unchanged and correct.

---------

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
Rod Boev 2026-07-08 22:31:25 -04:00 committed by GitHub
parent f663894f60
commit 42ebbc6cce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View file

@ -201,7 +201,8 @@ def _parse_judge_response(text: str) -> tuple[float, str]:
Tuple of (score, reasoning).
"""
reasoning = ""
score = 3.0 # Default to middle score if parsing fails
score: float | None = None
parsed = False
lines = text.strip().split("\n")
@ -222,9 +223,20 @@ def _parse_judge_response(text: str) -> tuple[float, str]:
score = float(match.group(1))
# Clamp to valid range
score = max(1.0, min(5.0, score))
parsed = True
except ValueError:
logger.warning(f"Could not parse score from: {score_text}")
if not parsed:
# Default to a failing score so unparseable judge output doesn't
# silently pass downstream `judge_score >= 3.0` checks.
logger.warning(
f"Could not parse a score from judge response, defaulting to 0.0 (fail): {text!r}"
)
score = 0.0
assert score is not None
# If no explicit reasoning found, use the whole text
if not reasoning:
reasoning = text.strip()

View file

@ -180,6 +180,19 @@ Score: 3.5"""
score, _ = _parse_judge_response(response)
assert score == 1.0
def test_parse_judge_response_unparseable_defaults_to_failing_score(self):
"""Unparseable judge output must default below the pass threshold.
Regression test for #1890: a missing/garbled "Score:" line used to
default to 3.0, which is exactly the `judge_score >= 3.0` pass
threshold in before_after.py, silently marking unparseable judge
responses as passing.
"""
response = "The model's response looks reasonable overall."
score, _ = _parse_judge_response(response)
assert score < 3.0
def test_simple_judge_exact_match(self):
"""Test simple judge with exact match."""
score, reasoning = simple_judge(