FIX: reject a threshold aggregator that does not combine scores - #2877
Open
fei (feiiiiii5) wants to merge 3 commits into
Open
fei (feiiiiii5) wants to merge 3 commits into
fei (feiiiiii5) wants to merge 3 commits into
Conversation
Roman Lutz (romanlutz)
approved these changes
Sep 28, 2026
Roman Lutz (romanlutz)
enabled auto-merge
September 28, 2026 12:52
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.
auto-merge was automatically disabled
September 28, 2026 16:40
Head branch was pushed to by a user without write access
This branch has not been deployed
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
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: