Skip to content

MAINT: Fix ty unsound-assignment findings in executor, scenario, converter and prompt_normalizer (UA-2) - #4544

Merged
Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
cpruijsen:ua2-unsound-assignment
Nov 21, 2026
Merged

Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
cpruijsen:ua2-unsound-assignment

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

UA-2 from #4402: the rest of pyrit/executor, plus pyrit/scenario, pyrit/converter and pyrit/prompt_normalizer.

Description

Resolve the seven UA-2 unsound-assignment findings and remove their files from the temporary ty override. #4402

Finding Fix
Decomposition converter Cast to list[str]. The tokenizer pattern has no capture groups.
TAP tree visualization Check that the stored value is a Tree or None.
Many-shot dataset Cast the bundled JSON to list[dict[str, str]].
JSON retry Preserve the parameter and return types at the retry decorator.
Prompt normalizer Cast the batch result to list[Message]. The supplied callback returns a Message.
Attack technique factory Check the converter configuration in create() and can_append_request_converter(). Creation can select an override and append converters. Compatibility inspects the baked request chain.
ASSERT policy Cast the resolved parameter to str | None. Parameter resolution supplies that type.

I chose the local batch cast to keep the change within UA-2. A generic batch helper would also require edits in the target and scorer packages. I used a cast for the bundled dataset because the tracked file supplies the expected shape. The alternative is to validate the schema each time the file loads.

None of the findings represented a runtime bug in normal use with the expected types. The two validation changes make malformed values raise TypeError. test_tap_attack_result_tree_visualization_rejects_invalid_metadata checks rejection of 0 and "invalid". test_tap_attack_result_tree_visualization_getter_returns_value checks that the getter returns the same Tree object, with and without a root. The factory tests are test_baked_value_that_is_not_a_converter_config_raises and test_can_append_request_converter_rejects_baked_value_that_is_not_a_converter_config.

Public Python API output

base | TAP tree_visualization=0 | 0
head | TAP tree_visualization=0 | TypeError: tree_visualization must be a Tree or None
base | Factory create with baked dict | {'request_converters': []}
head | Factory create with baked dict | TypeError: attack_converter_config must be an AttackConverterConfig
base | Factory can_append_request_converter with baked dict | AttributeError: 'dict' object has no attribute 'request_converters'
head | Factory can_append_request_converter with baked dict | TypeError: attack_converter_config must be an AttackConverterConfig

Checks

  • make ty (ty over pyrit and tests/unit): all checks passed.
  • pre-commit on the changed files: all hooks passed.
  • Unit tests for scenario, executor, converter, prompt_normalizer, prompt_target, score and exceptions: all passed.

Copilot AI balanced review requested due to automatic review settings November 21, 2026 17:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

One or more reviewer sessions failed, leaving the review evidence incomplete.

No open issues 🎉

What changed in this PR

Advances the staged rollout in #4402 by resolving seven ty unsound-assignment findings across PyRIT’s executor, scenario, converter, and prompt-normalizer components.

Changes:

  • Adds targeted casts and preserves callable parameter and return types through the JSON retry decorator.
  • Validates TAP tree metadata and attack converter configurations, with regression tests for malformed values.
  • Removes the seven resolved files from the temporary type-checking override.
File Description
tests/​unit/​scenario/​core/​test_attack_technique_factory.py Tests rejection of malformed converter configurations during compatibility checks.
tests/​unit/​scenario/​core/​test_attack_technique_factory_converter_composition.py Covers absent configurations and malformed values with or without extra converters.
tests/​unit/​executor/​attack/​multi_turn/​test_tree_of_attacks.py Tests empty and rooted trees, plus invalid metadata rejection.
pyrit/​scenario/​scenarios/​foundry/​assert_policy.py Casts the resolved system-prompt parameter to its declared type.
pyrit/​scenario/​core/​attack_technique_factory.py Validates converter configurations before compatibility checks and composition.
pyrit/​prompt_normalizer/​prompt_normalizer.py Casts batch results to the callback’s known message-list type.
pyrit/​prompt_normalizer/​json_retry.py Returns the now-typed retry result directly.
pyrit/​executor/​attack/​single_turn/​many_shot_jailbreak.py Casts the bundled dataset to its expected structure.
pyrit/​executor/​attack/​multi_turn/​tree_of_attacks.py Requires stored visualizations to be a Tree or None.
pyrit/​exceptions/​exception_classes.py Preserves callable types through pyrit_json_retry.
pyrit/​converter/​decomposition_converter.py Casts capture-free tokenizer results to list[str].
pyproject.toml Enables unsound-assignment checking for the seven resolved files.

Review effort: Balanced

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 21, 2026
Merged via the queue into microsoft:main with commit 3ad04fd Nov 21, 2026
65 checks passed
Roman Lutz (romanlutz) added a commit to romanlutz/PyRIT that referenced this pull request Nov 22, 2026
Resolve the pyproject.toml conflict with microsoft#4544 (UA-2): both changes remove
their own files from the temporary unsound-assignment override, so the
merged list drops the UA-2 and the GCG entries.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants