FIX: separator normalization for harm categories and likert invariants - #2670
Open
Saurabh Yadav (onlyysaurabh) wants to merge 1 commit into
Open
Saurabh Yadav (onlyysaurabh) wants to merge 1 commit into
Saurabh Yadav (onlyysaurabh) wants to merge 1 commit into
Conversation
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.
Fast-follow to PR #2663 addressing the residual items for Issue #2661 highlighted by varunj-msft:
casefold()fast path handled case-only differences (e.g.,Jailbreakvsjailbreak), but separator variations (HateSpeechvshate_speech,ProtectedMaterialvsprotected_material) still failed matching without hand-added aliases.metrics.harm_categorywere missing, allowing silentNoneregressions on direct-call paths.Summary of Changes
pyrit/models/harm_category.py):key.translate(_SEP_TRANS)where_SEP_TRANS = str.maketrans("", "", "_- ")) into_CANONICAL_LOOKUPalongside exact names and display values.HarmCategory._resolve_canonical_categoryperforms exact lookup first, then falls back to stripped lookup.HateSpeech->HATE_SPEECH,ProtectedMaterial->PROTECTED_MATERIAL,SelfHarm->SELF_HARM) automatically without needing manual entries in_HARM_CATEGORY_ALIASES.pyrit/score/scorer_evaluation/scorer_evaluator.py):_,-, and spaces from both sides in_score_matches_harm_categoryfast path:c.casefold().translate(_SEP_TRANS) == target_clean.PromptInjectionvsprompt_injection,jailbreak-attemptvsjailbreak_attempt) to match cleanly.tests/unit/score/test_self_ask_likert.py):LikertScalePathsthat haveevaluation_files is not None.scale.category == preset.evaluation_files.harm_category.tests/unit/score/test_scorer_evaluator.py):metrics.harm_category(assert metrics.harm_category == "hate_speech"andassert metrics.harm_category == "violence") intest_run_evaluation_async_*to guard againstNoneregressions.harmvsself_harm,selfvsself_harm,speechvshate_speech,codevsinsecure_code,cybervscyberattack) are strictly rejected withValueError.tests/unit/models/test_harm_category.py):HarmCategory.parsecleanly maps CamelCase, kebab-case, snake_case, and space variants directly into enum members.Tests and Documentation
uv run pytest tests/unit/score/test_scorer_evaluator.py tests/unit/score/test_self_ask_likert.py tests/unit/models/test_harm_category.py -q-> 171 passed in 6.00s
uv run pytest tests/unit/score/ tests/unit/models/ -q-> 3,201 passed, 0 failures, 0 regressions
uv run ruff check-> Passed (0 warnings, 0 errors)uv run ruff format --check-> Passed (All 5 files formatted)