Skip to content

FIX TrueFalseResponseHandler: strip whitespace before validating verdict - #2389

Open
WatchTree-19 wants to merge 2 commits into
microsoft:mainfrom
WatchTree-19:fix-truefalse-verdict-whitespace
Open

FIX TrueFalseResponseHandler: strip whitespace before validating verdict#2389
WatchTree-19 wants to merge 2 commits 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).

…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.
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.

1 participant