pyrit.scenarios.FoundryScenario#
- class FoundryScenario(*, objective_target: PromptTarget | None = None, scenario_strategies: Sequence[FoundryStrategy | ScenarioCompositeStrategy] | None = None, adversarial_chat: PromptChatTarget | None = None, objectives: list[str] | None = None, objective_scorer: TrueFalseScorer | None = None, memory_labels: Dict[str, str] | None = None, max_concurrency: int = 5)[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__(*, objective_target: PromptTarget | None = None, scenario_strategies: Sequence[FoundryStrategy | ScenarioCompositeStrategy] | None = None, adversarial_chat: PromptChatTarget | None = None, objectives: list[str] | None = None, objective_scorer: TrueFalseScorer | None = None, memory_labels: Dict[str, str] | None = None, max_concurrency: int = 5)[source]#
Initialize a FoundryScenario with the specified attack strategies.
- Parameters:
objective_target (PromptTarget) – The target system to attack.
scenario_strategies (list[FoundryStrategy | ScenarioCompositeStrategy] | None) – Strategies to test. Can be a list of FoundryStrategy enums (simple case) or ScenarioCompositeStrategy instances (advanced case for composition). If None, defaults to EASY strategies.
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.
memory_labels (Optional[Dict[str, str]]) – Additional labels to apply to all attack runs for tracking and categorization.
- Raises:
ValueError – If attack_strategies is empty or contains unsupported strategies.
Methods
__init__(*[, objective_target, ...])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()Initialize the scenario by populating self._atomic_attacks
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]