pyrit.executor.attack.AttackStrategy#
- class AttackStrategy(*, objective_target: ~pyrit.prompt_target.common.prompt_target.PromptTarget, context_type: type[~pyrit.executor.attack.core.attack_strategy.AttackStrategyContextT], logger: ~logging.Logger = <Logger ai-red-team (INFO)>)[source]#
Bases:
Strategy[AttackStrategyContextT,AttackStrategyResultT],ABCAbstract base class for attack strategies. Defines the interface for executing attacks and handling results.
- __init__(*, objective_target: ~pyrit.prompt_target.common.prompt_target.PromptTarget, context_type: type[~pyrit.executor.attack.core.attack_strategy.AttackStrategyContextT], logger: ~logging.Logger = <Logger ai-red-team (INFO)>)[source]#
Initialize the attack strategy with a specific context type and logger.
- Parameters:
objective_target (PromptTarget) – The target system to attack.
context_type (type[AttackStrategyContextT]) – The type of context this strategy operates on.
logger (logging.Logger) – Logger instance for logging events.
Methods
__init__(*, objective_target, context_type)Initialize the attack strategy with a specific context type and logger.
Execute the attack strategy asynchronously with the provided parameters.
execute_with_context_async(*, context)Execute strategy with complete lifecycle management.
Get the attack scoring configuration used by this strategy.
get_identifier()Get the objective target for this attack strategy.
- async execute_async(*, objective: str, prepended_conversation: list[Message] | None = None, memory_labels: dict[str, str] | None = None, **kwargs) AttackStrategyResultT[source]#
- async execute_async(**kwargs) AttackStrategyResultT
Execute the attack strategy asynchronously with the provided parameters.
- get_attack_scoring_config() AttackScoringConfig | None[source]#
Get the attack scoring configuration used by this strategy.
- Returns:
The scoring configuration, or None if not applicable.
- Return type:
Optional[AttackScoringConfig]
Note
Subclasses that use scoring should override this method to return their scoring configuration. The default implementation returns None.
- get_objective_target() PromptTarget[source]#
Get the objective target for this attack strategy.
- Returns:
The target system being attacked.
- Return type: