Skip to content

FIX TrueFalseResponseHandler: strip whitespace before validating verdict - #2389

Merged
Roman Lutz (romanlutz) merged 1 commit into
microsoft:mainfrom
WatchTree-19:fix-truefalse-verdict-whitespace
Aug 14, 2026
Merged

FIX TrueFalseResponseHandler: strip whitespace before validating verdict#2389
Roman Lutz (romanlutz) merged 1 commit into
microsoft:mainfrom
WatchTree-19:fix-truefalse-verdict-whitespace

Conversation

@WatchTree-19

Copy link
Copy Markdown
Contributor

Description

TrueFalseResponseHandler.parse lowercases the parsed score value but does not strip it before checking membership in {"true", "false"}:

normalized_value = score.raw_score_value.lower()
if normalized_value not in {"true", "false"}:
    raise InvalidJsonException(...)

raw_score_value comes straight from str(parsed_response[score_value_output_key]), so a judge that returns a valid verdict with incidental surrounding whitespace - "true\n", " false", "True " - is rejected as out-of-domain. Targets that do not natively enforce the JSON schema can easily emit this, and the result is that a usable true/false judgment is thrown away (and the JSON retry path is triggered, burning a call).

The numeric path already tolerates this, since float("3.0 ") succeeds; only the string-compared true/false domain is whitespace-sensitive.

Fix: strip() before lower() so incidental whitespace no longer invalidates an otherwise-valid verdict. The stored raw_score_value remains the clean "true"/"false".

Same class as #2133 (parse the raw score robustly before validating it).

Tests and Documentation

Added a parametrized regression test in tests/unit/score/test_response_handler.py covering "true ", " false", "True\n", and " FALSE " -> all now normalize to the expected verdict. Out-of-domain values (e.g. "refusal") are still rejected.

pytest tests/unit/score/test_response_handler.py tests/unit/score/test_self_ask_true_false.py tests/unit/score/test_general_true_false_scorer.py -> 46 passed. ruff and black clean. No documentation changes needed (internal parsing behavior only).

@WatchTree-19

Copy link
Copy Markdown
Contributor Author

hannahwestra25 if you have a moment - this is the same small scorer-hardening class as #2388 (thanks again for merging that one). here the true/false response handler lowercases the verdict but doesn't strip it, so a judge returning a valid true/false with trailing whitespace (e.g. true\n from a target that isn't schema-enforced) gets rejected as out-of-domain and the score is dropped. fix is .strip().lower(), with a regression test. CLA's green - i think it just needs a maintainer to approve the CI run on the fork. no rush, and happy to point it at whoever's best.

The true/false response handler lowercased the parsed score value but did
not strip it before checking membership in {"true", "false"}. A judge
returning a valid verdict with incidental surrounding whitespace - e.g.
'true\n', ' false', or 'True ' from a target that does not enforce the
JSON schema - was rejected as out-of-domain, discarding a usable score
(and triggering the JSON retry path).

Strip before lowercasing so incidental whitespace no longer invalidates an
otherwise-valid true/false verdict. Adds a parametrized regression test.
@WatchTree-19
WatchTree-19 force-pushed the fix-truefalse-verdict-whitespace branch from 3759fed to 7171c95 Compare August 14, 2026 22:26
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Aug 14, 2026
Merged via the queue into microsoft:main with commit e1107cc Aug 14, 2026
54 checks passed
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