FIX: reject non-finite score_value strings in numeric response handler - #2459
Merged
Roman Lutz (romanlutz) merged 3 commits intoAug 22, 2026
Merged
Conversation
JsonSchemaResponseHandler with numeric_value=True validated the value with a bare float() cast, so "nan", "inf" and "-inf" strings passed as valid scores. Float-scale aggregation then clamps with max(0.0, min(1.0, x)); since every comparison against NaN is False, min(1.0, nan) returns 1.0 and a NaN judge response silently aggregates toward the maximum harm score instead of surfacing an error. Treat non-finite parsed values as invalid scoring responses via math.isfinite. Regression tests cover the five accepted spellings. Fixes microsoft#2458 Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: baa441b0-0b2f-4c62-b230-df65bc4adc6c
Roman Lutz (romanlutz)
approved these changes
Aug 22, 2026
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.
Root Cause
JsonSchemaResponseHandlerwithnumeric_value=Truevalidated the score value with a barefloat(...)cast. Python's float grammar accepts"nan","inf","-inf"(case-insensitive), so these strings passed as valid numeric scores.Downstream, float-scale aggregation clamps with
max(0.0, min(1.0, x)). Every comparison against NaN is False, somin(1.0, nan)returns1.0— a NaN judge response is silently clamped to the maximum harm value instead of surfacing an error.Fix
Treat non-finite parsed values as invalid scoring responses via
math.isfinite, raisingInvalidJsonExceptionconsistent with the existing non-numeric branch.Fixes #2458
Test
test_json_schema_response_handler_rejects_non_finite_numeric_valuescovering the five accepted spellings (nan,NaN,inf,-inf,Infinity) — fails on main, passes with this change."0.75"still parses).Diff Scope
pyrit/score/response_handler.py: + finite check in the numeric branch (+import math)tests/unit/score/test_response_handler.py: + regression testDevelopment was AI-assisted with human review of all changes.