pyrit.scenario.FoundryScenario#
- class FoundryScenario(*, adversarial_chat: PromptChatTarget | None = None, objectives: list[str] | None = None, objective_scorer: TrueFalseScorer | None = None, include_baseline: bool = True, scenario_result_id: str | None = None)[source]#
Bases:
ScenarioFoundryScenario is a preconfigured scenario that automatically generates multiple AtomicAttack instances based on the specified attack strategies. It supports both single-turn attacks (with various converters) and multi-turn attacks (Crescendo, RedTeaming), making it easy to quickly test a target against multiple attack vectors.
The scenario can expand difficulty levels (EASY, MODERATE, DIFFICULT) into their constituent attack strategies, or you can specify individual strategies directly.
Note this is not the same as the Foundry AI Red Teaming Agent. This is a PyRIT contract so their library can make use of PyRIT in a consistent way.
- __init__(*, adversarial_chat: PromptChatTarget | None = None, objectives: list[str] | None = None, objective_scorer: TrueFalseScorer | None = None, include_baseline: bool = True, scenario_result_id: str | None = None)[source]#
Initialize a FoundryScenario with the specified attack strategies.
- Parameters:
adversarial_chat (Optional[PromptChatTarget]) – Target for multi-turn attacks like Crescendo and RedTeaming. Additionally used for scoring defaults. If not provided, a default OpenAI target will be created using environment variables.
objectives (Optional[list[str]]) – List of attack objectives/prompts to test. If not provided, defaults to 4 random objectives from the HarmBench dataset.
objective_scorer (Optional[TrueFalseScorer]) – Scorer to evaluate attack success. If not provided, creates a default composite scorer using Azure Content Filter and SelfAsk Refusal scorers.
include_baseline (bool) – Whether to include a baseline atomic attack that sends all objectives without modifications. Defaults to True. When True, a “baseline” attack is automatically added as the first atomic attack, allowing comparison between unmodified prompts and attack-modified prompts.
scenario_result_id (Optional[str]) – Optional ID of an existing scenario result to resume.
- Raises:
ValueError – If attack_strategies is empty or contains unsupported strategies.
Methods
__init__(*[, adversarial_chat, objectives, ...])Initialize a FoundryScenario with the specified attack strategies.
Get the default strategy used when no strategies are specified.
Get the strategy enum class for this scenario.
initialize_async(*[, objective_target, ...])Initialize the scenario by populating self._atomic_attacks and creating the ScenarioResult.
run_async()Execute all atomic attacks in the scenario sequentially.
Attributes
atomic_attack_countGet the number of atomic attacks in this scenario.
nameGet the name of the scenario.
- classmethod get_default_strategy() ScenarioStrategy[source]#
Get the default strategy used when no strategies are specified.
- Returns:
FoundryStrategy.EASY (easy difficulty strategies).
- Return type:
- classmethod get_strategy_class() Type[ScenarioStrategy][source]#
Get the strategy enum class for this scenario.
- Returns:
The FoundryStrategy enum class.
- Return type:
Type[ScenarioStrategy]