Repository navigation
MAINT: Fix unsound-assignment findings in pyrit/score (UA-5) - #4519
Merged
Roman Lutz (romanlutz) merged 7 commits intoNov 22, 2026
Merged
Roman Lutz (romanlutz) merged 7 commits into
Roman Lutz (romanlutz) merged 7 commits into
Conversation
Fix the seven ty unsound-assignment findings in pyrit/score and remove those files from the temporary override. Values typed by construction are cast with a comment stating why; the Prompt Shield response's userPromptAnalysis field is validated with a clear error and a regression test. The pyrit_json_retry decorator preserves the decorated function's signature instead of erasing it to Any, which made the call sites unchecked and also accounts for the finding in prompt_normalizer/json_retry.py. Part of microsoft#4402 (UA-5). Signed-off-by: sainimal1ba-hue <230497022+sainimal1ba-hue@users.noreply.github.com>
Contributor
Author
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The parser-only test leaves the public score_text_async failure behavior—a RuntimeError caused by ValueError—and malformed falsy responses such as null or [] untested.
1 open issue
What changed in this PR
This PR completes UA-5 of #4402, addressing seven unsound-assignment findings in PyRIT’s scoring layer and enabling the rule for those files.
Changes:
- Preserve decorated function signatures in
pyrit_json_retry. - Add documented casts where types are guaranteed by construction.
- Validate Prompt Shield’s
userPromptAnalysisfield and add a rejection test.
| File | Description |
|---|---|
tests/unit/score/test_prompt_shield_scorer.py |
Adds malformed-response rejection coverage. |
pyrit/score/true_false/prompt_shield_scorer.py |
Validates userPromptAnalysis before parsing detections. |
pyrit/score/scorer.py |
Casts legacy hook results and dynamic target lookups. |
pyrit/score/scorer_prompt_validator.py |
Casts roles derived from the role type. |
pyrit/score/observation/otel_execution_trace_source.py |
Casts regex split results used for natural sorting. |
pyrit/score/float_scale/local_violence_classifier_scorer.py |
Casts tensor-derived embedding lists. |
pyrit/exceptions/exception_classes.py |
Preserves signatures through the JSON retry decorator. |
pyproject.toml |
Removes six score files from the temporary typing override. |
Review effort: Balanced
…ing path null and [] used to come back as a negative detection, and the failure behavior through score_text_async was untested. Signed-off-by: sainimal1ba-hue <230497022+sainimal1ba-hue@users.noreply.github.com>
a12san (sainimal1ba-hue)
force-pushed
the
ua5-score-unsound-assignment
branch
from
November 21, 2026 11:08
083e5d2 to
83a7a50
Compare
Roman Lutz (romanlutz)
approved these changes
Nov 21, 2026
Roman Lutz (romanlutz)
enabled auto-merge
November 21, 2026 19:09
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 21, 2026
Contributor
Author
|
resolved the conflicts |
…ieldScorer The sibling field one line below the UA-5 fix had the same hazard: a truthy non-list crashed in the detection comprehension and a falsy non-list silently scored [False]. Reject both with the same ValueError treatment, covered through the public scoring path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Roman Lutz (romanlutz)
enabled auto-merge
November 22, 2026 07:05
Roman Lutz (romanlutz)
added a commit
to romanlutz/PyRIT
that referenced
this pull request
Nov 23, 2026
Resolve the pyproject.toml conflict with UA-3, UA-4, UA-5 and UA-7 (microsoft#4520, microsoft#4537, microsoft#4519, microsoft#4517): each change removes its own files from the temporary unsound-assignment override, so the merged list drops those and the GCG entries and keeps only the UA-6 files. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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
UA-5 for #4402: fixes the seven ty
unsound-assignmentfindings inpyrit/scoreand removes the score files from the temporary override. Rebased on currentmain(a943e99).scorer.py(2): the legacy hook call and the_prompt_targetlookup hand backAny; both arecastwith a comment stating why the type is guaranteed.llm_scoring.py(1): fixed at the source.pyrit_json_retryerased the decorated function's signature toCallable[..., Any], which left theUnvalidatedScorereturn unchecked; the decorator now preserves the signature with the sameParamSpec/TypeVarpairpyrit_target_retryalready uses. This also covers the identical shape inprompt_normalizer/json_retry.py, which stays on the override for UA-2.true_false/prompt_shield_scorer.py(1):userPromptAnalysisis now validated. Absent,Falseor a dict passes, anything else raisesValueError, with a regression test for the rejected case.float_scale/local_violence_classifier_scorer.py(1),observation/otel_execution_trace_source.py(1) andscorer_prompt_validator.py(1): values typed by construction arecastwith comments (torch'stolist()is untyped in the stubs,re.splitwidens its element type for patterns with capture groups,get_argsreturnsAny).No
# type: ignoreadded and no annotation weakened toAny.Testing
ty check pyritpasses with the score files off the override. Reverting the six score files and the decorator on this branch brings back exactly the seven findings, so the fixes are what keep the check green.pytest tests/unit/scorepasses (7272 tests).