Repository navigation
FIX: reject a threshold aggregator that does not combine scores - #2877
Roman Lutz (romanlutz) merged 7 commits into
Conversation
The pre-commit ty check flags every __name__ read on a callable, and this file already silences the two pre-existing ones with the same rule id.
Head branch was pushed to by a user without write access
|
Hi Pyrit maintainers — this one has been open since 22 September with a green CI and no response, so this is the one nudge I planned. The short version: The one thing I could not settle from inside the code, and would rather ask than guess: should the guard live where I put it (the threshold scorer, matching those two neighbours), or in the Two regression tests are in |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
a12c880
into
microsoft:main
Description
FloatScaleThresholdScoreraccepts anyFloatScaleAggregatorFuncbut only ever used the first result:FloatScaleScorerByCategory.MAXis exported frompyrit.scoreand is the sameFloatScaleAggregatorFunctype as the defaultFloatScaleScoreAggregator.MAX, but returns one result per harm category instead of combining them. Wrapping a per-category scorer in a threshold scorer produced a singleTrue/Falseverdict decided by whichever category sorted first, the other categories dropped with no log, metadata key or second score. ThresholdingHate: 0.0andViolence: 0.9at0.5returns:In a red-teaming run that reads as "not harmful" when a category is well over the threshold.
Two components here already refuse this instead of guessing:
TrueFalseCompositeScorerraisesValueError("Each TrueFalseScorer must return exactly one score.")andFallbackScorerraises"...aggregate multiple results first.". This makes the threshold scorer consistent with them, and turns the empty-aggregate case into the same clear error instead ofIndexError: list index out of range.Tests and Documentation
Two tests in
tests/unit/score/test_float_scale_threshold_scorer.py: a by-category aggregator is rejected with a message naming it, and an aggregator returning nothing is rejected rather than raisingIndexError. Docstrings forfloat_scale_aggregatorand_apply_thresholdstate the requirement.Command output
With only the tests added, on
mainat7b533109:The second failed with
Actual message: 'Error in scorer FloatScaleThresholdScorer: list index out of range'; the first did not raise at all and returned theFalseverdict above.After: