FIX TrueFalseResponseHandler: strip whitespace before validating verdict - #2389
Open
WatchTree-19 wants to merge 2 commits into
Open
FIX TrueFalseResponseHandler: strip whitespace before validating verdict#2389WatchTree-19 wants to merge 2 commits into
WatchTree-19 wants to merge 2 commits into
Conversation
…strings
The verbatim-match shortcut in _plagiarism_score used a raw string check
(reference in response). The rest of the scorer is word-level: it tokenizes
with lowercasing and punctuation removal before computing LCS / Levenshtein /
Jaccard. The raw check was inconsistent with that in both directions:
- false positive: a short reference that is only a substring of a longer
response word scored 1.0 (e.g. reference 'cat' vs response 'concatenate
the results' returned full plagiarism for every metric).
- missed match: a word-level verbatim copy differing only in case or
punctuation did not take the fast path.
Compare the tokenized sequences instead, so the fast path matches the same
word-level semantics the metrics use. Adds regression tests.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
TrueFalseResponseHandler.parselowercases the parsed score value but does not strip it before checking membership in{"true", "false"}:raw_score_valuecomes straight fromstr(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()beforelower()so incidental whitespace no longer invalidates an otherwise-valid verdict. The storedraw_score_valueremains 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.pycovering"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.ruffandblackclean. No documentation changes needed (internal parsing behavior only).