Skip to content

Commit af4ef9e

Browse files
Rename BASELINE_POLICY to BASELINE_ATTACK_POLICY for clarity
Addresses review feedback from PR #1760 requesting a more descriptive name for the class variable that controls baseline attack inclusion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ea7ba88 commit af4ef9e

13 files changed

Lines changed: 27 additions & 27 deletions

.github/instructions/scenarios.instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ Scenarios orchestrate multi-attack security testing campaigns. Each scenario gro
1111
All scenarios inherit from `Scenario` (ABC) and must:
1212

1313
1. **Define `VERSION`** as a class constant (increment on breaking changes)
14-
2. **Optionally declare `BASELINE_POLICY`** (defaults to `BaselinePolicy.Enabled` — a baseline `PromptSendingAttack` is prepended and callers can opt out per run via `initialize_async(include_baseline=False)`):
14+
2. **Optionally declare `BASELINE_ATTACK_POLICY`** (defaults to `BaselinePolicy.Enabled` — a baseline `PromptSendingAttack` is prepended and callers can opt out per run via `initialize_async(include_baseline=False)`):
1515
- `BaselinePolicy.Disabled` — baseline supported but off by default (e.g. `Jailbreak`, where templates dominate the run).
1616
- `BaselinePolicy.Forbidden` — baseline is meaningless for this scenario's comparison axis (e.g. `AdversarialBenchmark`, which compares against gold-standard answers). Explicit `include_baseline=True` raises `ValueError`.
1717
3. **Implement three abstract methods:**
1818

1919
```python
2020
class MyScenario(Scenario):
2121
VERSION: int = 1
22-
BASELINE_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Enabled
22+
BASELINE_ATTACK_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Enabled
2323

2424
@classmethod
2525
def get_strategy_class(cls) -> type[ScenarioStrategy]:

doc/code/scenarios/0_scenarios.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
" - `max_retries`: Number of retry attempts on failure (default: 0)\n",
8484
" - `memory_labels`: Optional labels for tracking (optional)\n",
8585
" - `include_baseline`: Whether to prepend a baseline attack (defaults to the scenario type's\n",
86-
" `BASELINE_POLICY`; most scenarios default it on, `Jailbreak` defaults it off)\n",
86+
" `BASELINE_ATTACK_POLICY`; most scenarios default it on, `Jailbreak` defaults it off)\n",
8787
"\n",
8888
"### Example Structure\n",
8989
"\n",
@@ -406,11 +406,11 @@
406406
"Every scenario can optionally include a **baseline attack** — a `PromptSendingAttack` that sends\n",
407407
"each objective directly to the target without any converters or multi-turn techniques. This is\n",
408408
"controlled by the `include_baseline` parameter on `initialize_async`; when omitted, each\n",
409-
"scenario falls back to its own `BASELINE_POLICY` class attribute (most scenarios default\n",
409+
"scenario falls back to its own `BASELINE_ATTACK_POLICY` class attribute (most scenarios default\n",
410410
"it on; `Jailbreak` defaults it off). See\n",
411411
"[Common Scenario Parameters](./1_common_scenario_parameters.ipynb) for a worked example.\n",
412412
"\n",
413-
"Custom scenarios should choose their `BASELINE_POLICY` based on whether an unmodified\n",
413+
"Custom scenarios should choose their `BASELINE_ATTACK_POLICY` based on whether an unmodified\n",
414414
"prompt is a meaningful comparator for the scenario's strategies:\n",
415415
"\n",
416416
"- **`Enabled`** — the baseline is prepended by default and the caller can opt out. Use when an\n",

doc/code/scenarios/0_scenarios.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
# - `max_retries`: Number of retry attempts on failure (default: 0)
8686
# - `memory_labels`: Optional labels for tracking (optional)
8787
# - `include_baseline`: Whether to prepend a baseline attack (defaults to the scenario type's
88-
# `BASELINE_POLICY`; most scenarios default it on, `Jailbreak` defaults it off)
88+
# `BASELINE_ATTACK_POLICY`; most scenarios default it on, `Jailbreak` defaults it off)
8989
#
9090
# ### Example Structure
9191
#
@@ -176,11 +176,11 @@ def _build_display_group(self, *, technique_name: str, seed_group_name: str) ->
176176
# Every scenario can optionally include a **baseline attack** — a `PromptSendingAttack` that sends
177177
# each objective directly to the target without any converters or multi-turn techniques. This is
178178
# controlled by the `include_baseline` parameter on `initialize_async`; when omitted, each
179-
# scenario falls back to its own `BASELINE_POLICY` class attribute (most scenarios default
179+
# scenario falls back to its own `BASELINE_ATTACK_POLICY` class attribute (most scenarios default
180180
# it on; `Jailbreak` defaults it off). See
181181
# [Common Scenario Parameters](./1_common_scenario_parameters.ipynb) for a worked example.
182182
#
183-
# Custom scenarios should choose their `BASELINE_POLICY` based on whether an unmodified
183+
# Custom scenarios should choose their `BASELINE_ATTACK_POLICY` based on whether an unmodified
184184
# prompt is a meaningful comparator for the scenario's strategies:
185185
#
186186
# - **`Enabled`** — the baseline is prepended by default and the caller can opt out. Use when an

pyrit/scenario/core/scenario.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BaselinePolicy(Enum):
6161
6262
The baseline is a plain ``PromptSendingAttack`` that sends each objective unmodified,
6363
used as a comparison point against the scenario's strategies. Each scenario class
64-
declares its policy via ``Scenario.BASELINE_POLICY``; callers can still override
64+
declares its policy via ``Scenario.BASELINE_ATTACK_POLICY``; callers can still override
6565
at runtime via ``initialize_async(include_baseline=...)`` for the ``Enabled`` and
6666
``Disabled`` states.
6767
"""
@@ -145,7 +145,7 @@ class Scenario(ABC):
145145
#: ``initialize_async`` and overridable per run via ``include_baseline`` for the
146146
#: ``Enabled`` and ``Disabled`` states; ``Forbidden`` is a hard constraint and a
147147
#: caller-supplied ``include_baseline=True`` raises ``ValueError``.
148-
BASELINE_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Enabled
148+
BASELINE_ATTACK_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Enabled
149149

150150
@classmethod
151151
def _get_additional_scoring_questions(cls) -> Sequence[Path]:
@@ -621,14 +621,14 @@ async def initialize_async(
621621
include_baseline (bool | None): Whether to prepend a baseline atomic attack that sends
622622
all objectives without modifications, allowing comparison between unmodified prompts
623623
and the scenario's strategies. If None (the default), the scenario type's
624-
``BASELINE_POLICY`` class attribute decides: ``Enabled`` includes it,
624+
``BASELINE_ATTACK_POLICY`` class attribute decides: ``Enabled`` includes it,
625625
``Disabled`` omits it, and ``Forbidden`` always omits it (and rejects an
626-
explicit ``True``). Passing ``True`` to a scenario whose ``BASELINE_POLICY``
626+
explicit ``True``). Passing ``True`` to a scenario whose ``BASELINE_ATTACK_POLICY``
627627
is ``Forbidden`` raises ``ValueError``.
628628
629629
Raises:
630630
ValueError: If no objective_target is provided, or if ``include_baseline=True`` is passed
631-
to a scenario whose ``BASELINE_POLICY`` is ``Forbidden``.
631+
to a scenario whose ``BASELINE_ATTACK_POLICY`` is ``Forbidden``.
632632
"""
633633
# Validate required parameters
634634
if objective_target is None:
@@ -657,15 +657,15 @@ async def initialize_async(
657657
# scenario type never silently inherits a True default; explicit-True on a forbidden
658658
# type is a hard error rather than a silent ignore. For the Enabled / Disabled states,
659659
# a None runtime value defers to the policy.
660-
if self.BASELINE_POLICY is BaselinePolicy.Forbidden:
660+
if self.BASELINE_ATTACK_POLICY is BaselinePolicy.Forbidden:
661661
if include_baseline is True:
662662
raise ValueError(
663663
f"{type(self).__name__} does not support a default baseline "
664-
f"(BASELINE_POLICY = Forbidden); pass include_baseline=False or omit the argument."
664+
f"(BASELINE_ATTACK_POLICY = Forbidden); pass include_baseline=False or omit the argument."
665665
)
666666
include_baseline = False
667667
elif include_baseline is None:
668-
include_baseline = self.BASELINE_POLICY is BaselinePolicy.Enabled
668+
include_baseline = self.BASELINE_ATTACK_POLICY is BaselinePolicy.Enabled
669669

670670
self._include_baseline = include_baseline
671671

pyrit/scenario/scenarios/benchmark/adversarial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AdversarialBenchmark(Scenario):
3737

3838
#: AdversarialBenchmark compares attack-success rates across adversarial models; a baseline
3939
#: attack would be model-independent and contribute no signal to the comparison.
40-
BASELINE_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Forbidden
40+
BASELINE_ATTACK_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Forbidden
4141

4242
@classmethod
4343
def get_strategy_class(cls) -> type[ScenarioStrategy]:

tests/unit/scenario/test_adversarial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ async def test_baseline_excluded(self, mock_objective_target, single_adversarial
466466
mock_objective_target=mock_objective_target,
467467
adversarial_models=single_adversarial_model,
468468
)
469-
assert type(scenario).BASELINE_POLICY is BaselinePolicy.Forbidden
469+
assert type(scenario).BASELINE_ATTACK_POLICY is BaselinePolicy.Forbidden
470470
assert not any(a.atomic_attack_name == "baseline" for a in scenario._atomic_attacks)
471471

472472
async def test_baseline_explicit_true_raises(self, mock_objective_target, single_adversarial_model):

tests/unit/scenario/test_baseline_deprecation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_aggregate_tags(cls) -> set[str]:
3434
class _LegacyScenario(Scenario):
3535
"""Minimal Scenario stand-in for exercising the deprecated baseline kwargs."""
3636

37-
BASELINE_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Enabled
37+
BASELINE_ATTACK_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Enabled
3838

3939
def __init__(self, **kwargs):
4040
kwargs.setdefault("strategy_class", _LegacyStrategy)
@@ -99,7 +99,7 @@ def test_base_kwarg_omitted_emits_no_warning(self):
9999
assert scenario._legacy_include_baseline is None
100100

101101
async def test_legacy_value_drives_initialize_when_runtime_kwarg_omitted(self, mock_objective_target):
102-
"""Constructor-time False suppresses the baseline that BASELINE_POLICY=Enabled would add."""
102+
"""Constructor-time False suppresses the baseline that BASELINE_ATTACK_POLICY=Enabled would add."""
103103
with warnings.catch_warnings():
104104
warnings.simplefilter("ignore", DeprecationWarning)
105105
scenario = _LegacyScenario(include_default_baseline=False)

tests/unit/scenario/test_jailbreak.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ async def test_init_raises_exception_when_no_datasets_available(self, mock_objec
205205

206206
def test_class_inherits_default_baseline_policy(self):
207207
"""Jailbreak inherits the base default (Enabled) — baseline included by default."""
208-
assert Jailbreak.BASELINE_POLICY is BaselinePolicy.Enabled
208+
assert Jailbreak.BASELINE_ATTACK_POLICY is BaselinePolicy.Enabled
209209

210210
async def test_default_initialize_includes_baseline(
211211
self, mock_objective_target, mock_objective_scorer, mock_memory_seed_groups
212212
):
213-
"""initialize_async without include_baseline honors BASELINE_POLICY=Enabled."""
213+
"""initialize_async without include_baseline honors BASELINE_ATTACK_POLICY=Enabled."""
214214
with patch.object(Jailbreak, "_resolve_seed_groups", return_value=mock_memory_seed_groups):
215215
scenario = Jailbreak(objective_scorer=mock_objective_scorer)
216216
await scenario.initialize_async(objective_target=mock_objective_target)

tests/unit/scenario/test_leakage_scenario.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_default_scorer_uses_leakage_yaml(self):
105105

106106
def test_init_supports_default_baseline(self):
107107
"""Leakage opts into the parent's default baseline."""
108-
assert Leakage.BASELINE_POLICY is BaselinePolicy.Enabled
108+
assert Leakage.BASELINE_ATTACK_POLICY is BaselinePolicy.Enabled
109109

110110

111111
@pytest.mark.usefixtures(*FIXTURES)

tests/unit/scenario/test_scenario.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ConcreteScenario(Scenario):
100100

101101
# Tests using this fixture should default to no baseline; set the class policy to Forbidden
102102
# so we don't have to thread include_baseline=False through every initialize_async call.
103-
BASELINE_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Forbidden
103+
BASELINE_ATTACK_POLICY: ClassVar[BaselinePolicy] = BaselinePolicy.Forbidden
104104

105105
def __init__(self, atomic_attacks_to_return=None, **kwargs):
106106
# Add required strategy_class if not provided

0 commit comments

Comments
 (0)