pyrit.executor.attack.PromptSendingAttack#
- class PromptSendingAttack(*, objective_target: PromptTarget, attack_converter_config: AttackConverterConfig | None = None, attack_scoring_config: AttackScoringConfig | None = None, prompt_normalizer: PromptNormalizer | None = None, max_attempts_on_failure: int = 0)[source]#
Bases:
SingleTurnAttackStrategy
Implementation of single-turn prompt sending attack strategy.
This class orchestrates a single-turn attack where malicious prompts are injected to try to achieve a specific objective against a target system. The strategy evaluates the target response using optional scorers to determine if the objective has been met.
The attack flow consists of: 1. Preparing the prompt based on the objective. 2. Sending the prompt to the target system through optional converters. 3. Evaluating the response with scorers if configured. 4. Retrying on failure up to the configured number of retries. 5. Returning the attack result with achievement status.
The strategy supports customization through prepended conversations, converters, and multiple scorer types for comprehensive evaluation.
- __init__(*, objective_target: PromptTarget, attack_converter_config: AttackConverterConfig | None = None, attack_scoring_config: AttackScoringConfig | None = None, prompt_normalizer: PromptNormalizer | None = None, max_attempts_on_failure: int = 0) None [source]#
Initialize the prompt injection attack strategy.
- Parameters:
objective_target (PromptTarget) – The target system to attack.
attack_converter_config (Optional[AttackConverterConfig]) – Configuration for prompt converters.
attack_scoring_config (Optional[AttackScoringConfig]) – Configuration for scoring components.
prompt_normalizer (Optional[PromptNormalizer]) – Normalizer for handling prompts.
max_attempts_on_failure (int) – Maximum number of attempts to retry on failure.
- Raises:
ValueError – If the objective scorer is not a true/false scorer.
Methods
__init__
(*, objective_target[, ...])Initialize the prompt injection attack strategy.
execute_async
(**kwargs)Execute the attack strategy asynchronously with the provided parameters.
execute_with_context_async
(*, context)Execute strategy with complete lifecycle management.
get_identifier
()