Repository navigation
MAINT: Extract attack factory adversarial configuration assembly (#2765) - #4206
eruguvidhant-ctrl wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A reST role in attack_technique_factory.py fails the pre-commit CI check and should be replaced with a plain double-backtick code span.
1 open issue
What changed in this PR
Extracts adversarial configuration assembly into a private technique-layer helper, simplifying AttackTechniqueFactory while preserving its public interface and existing configuration behavior.
Changes:
- Moves target selection, prompt precedence, conflict validation, and conditional configuration construction into the helper.
- Delegates the existing factory paths to the helper.
- Adds 16 unit tests covering precedence, conflicts, lazy target resolution, and prefix propagation.
| File | Description |
|---|---|
tests/unit/scenario/core/test_attack_adversarial_config.py |
Adds focused tests for the extracted helper. |
pyrit/scenario/core/attack_technique_factory.py |
Delegates adversarial configuration validation and assembly. |
pyrit/scenario/core/_attack_adversarial_config.py |
Introduces the private configuration helper. |
Review effort: Balanced
| create-time values, so a technique keeps its bespoke persona while a scenario can still | ||
| supply the target. | ||
|
|
||
| Delegates configuration assembly to :class:`_AttackAdversarialConfigHelper`. |
|
eruguvidhant-ctrl thanks for the contribution! Before we can review this PR, please accept the Microsoft Contributor License Agreement (CLA) by replying here with |
@microsoft-github-policy-service agree |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ig helper Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Summary
Extracts adversarial configuration assembly and conflict validation from
AttackTechniqueFactoryinto a dedicated private helper class_AttackAdversarialConfigHelperat the technique layer (pyrit/scenario/core/_attack_adversarial_config.py).Closes #2765.
Problem
AttackTechniqueFactory.create()and_build_adversarial_config()combined adversarial target selection, prompt resolution, conflicting-override checks, and attack construction within the factory class. These configuration and validation rules can be isolated into a cohesive helper without altering attack behavior or the factory's public interface.Solution
_AttackAdversarialConfigHelper(pyrit/scenario/core/_attack_adversarial_config.py):validate_target_conflict), preventing create-time targets when a custom target is already baked into the technique.validate_prompt_conflict), preventing create-time system/seed/template prompts when custom prompts are already baked into the technique.should_build_adversarial_config) based on accepted constructor parameters,uses_adversarialflag, or active adversarial overrides.AttackAdversarialConfiginstances lazily (build_adversarial_config), supporting an optional default target resolver.AttackTechniqueFactory:_adversarial_config_helperproperty reflecting current factory state.create()and configuration assembly in_build_adversarial_config()to the helper.tests/unit/scenario/core/test_attack_adversarial_config.pywith 16 test cases covering:ValueErroron conflicting baked and create-time targets.ValueErrorwhen custom prompts are already baked.Testing
tests/unit/scenario/core/test_attack_adversarial_config.py: 16 passedtests/unit/scenario/core/test_attack_technique_factory.py: 103 passedruff check(0 errors) and formatted withruff format.ty check(0 errors).