REFACTOR: Promote multi-turn attack constants & defaults to ClassVar - #1968
Closed
Roman Lutz (romanlutz) wants to merge 1 commit into
Closed
Conversation
Continues the constants-audit cleanup (microsoft#1964, microsoft#1965) by promoting the module-level _ADVERSARIAL_REQUIREMENTS sentinels and hard-coded constructor defaults (max_turns, max_backtracks, tree_width, tree_depth, branching_factor, desired_response_prefix, batch_size) in crescendo, red_teaming, tree_of_attacks and pair onto the owning attack classes as ClassVars, using the sentinel-default pattern for hyperparameters so docstrings reference the DEFAULT_* symbols. No value changes. No behaviour changes. Verified: ruff / ty / pytest tests/unit/executor/attack/multi_turn/. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Closing per maintainer feedback on the constants-audit work. This PR mixed two concerns: (1) the A-4 portion — promoting the module-level Branch |
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.
Continues the constants-audit cleanup established by #1964 (backend / registry / setup) and #1965 (prompt_converter). This PR combines two tracks for the multi-turn attacks so reviewers see the full picture per attack class:
_ADVERSARIAL_REQUIREMENTSTargetRequirementssentinel onto the owning attack class as aClassVar.DEFAULT_*ClassVars, using the sentinel-default pattern (x: int | None = None, thenif x is None: x = self.DEFAULT_X) so values remain inheritable/overridable and stay self-documenting.Files
pyrit/executor/attack/multi_turn/crescendo.py_ADVERSARIAL_REQUIREMENTS→CrescendoAttack._ADVERSARIAL_REQUIREMENTS: ClassVar[TargetRequirements]max_backtracks: int = 10→DEFAULT_MAX_BACKTRACKS: ClassVar[int] = 10max_turns: int = 10→DEFAULT_MAX_TURNS: ClassVar[int] = 10pyrit/executor/attack/multi_turn/red_teaming.py_ADVERSARIAL_REQUIREMENTS→RedTeamingAttack._ADVERSARIAL_REQUIREMENTS: ClassVar[TargetRequirements]max_turns: int = 10→DEFAULT_MAX_TURNS: ClassVar[int] = 10pyrit/executor/attack/multi_turn/tree_of_attacks.py_ADVERSARIAL_REQUIREMENTS→TreeOfAttacksWithPruningAttack._ADVERSARIAL_REQUIREMENTS: ClassVar[TargetRequirements]tree_width: int = 3→DEFAULT_TREE_WIDTH: ClassVar[int] = 3tree_depth: int = 5→DEFAULT_TREE_DEPTH: ClassVar[int] = 5branching_factor: int = 2→DEFAULT_BRANCHING_FACTOR: ClassVar[int] = 2desired_response_prefix: str = "Sure, here is"→DEFAULT_DESIRED_RESPONSE_PREFIX: ClassVar[str] = "Sure, here is"batch_size: int = 10→DEFAULT_BATCH_SIZE: ClassVar[int] = 10pyrit/executor/attack/multi_turn/pair.py(Track B only — no module-level_ADVERSARIAL_REQUIREMENTSexisted here)tree_width: int = 3→PAIRAttack.DEFAULT_TREE_WIDTH: ClassVar[int] = 3tree_depth: int = 5→PAIRAttack.DEFAULT_TREE_DEPTH: ClassVar[int] = 5desired_response_prefix: str = "Sure, here is"→PAIRAttack.DEFAULT_DESIRED_RESPONSE_PREFIX: ClassVar[str] = "Sure, here is"batch_size: int = 10→PAIRAttack.DEFAULT_BATCH_SIZE: ClassVar[int] = 10Docstrings updated to point at the
DEFAULT_*symbols (e.g.tree_width: defaults to ``DEFAULT_TREE_WIDTH`` (3)). Public call signatures stay keyword-only with the same parameter names; only the defaults moved from inline literals to class attributes.No value or behaviour changes
Pure structural rename. All literals preserved; same defaults applied via the sentinel pattern. Validation order is preserved (
is Nonesubstitution runs before existing positive/non-negative range checks).Verified
All green —
319 passedin the multi_turn test suite, ruff/ty clean.