pyrit.executor.attack.AttackParameters#
- class AttackParameters(objective: str, next_message: ~pyrit.models.message.Message | None = None, prepended_conversation: ~typing.List[~pyrit.models.message.Message] | None = None, memory_labels: ~typing.Dict[str, str] | None = <factory>)[source]#
Bases:
objectImmutable parameters for attack execution.
This class defines the standard contract for attack parameters. All attacks at a given level of the hierarchy share the same parameter signature.
Attacks that don’t accept certain parameters should use the excluding() factory to create a derived params type without those fields. Attacks that need additional parameters should extend this class with new fields.
- __init__(objective: str, next_message: ~pyrit.models.message.Message | None = None, prepended_conversation: ~typing.List[~pyrit.models.message.Message] | None = None, memory_labels: ~typing.Dict[str, str] | None = <factory>) None#
Methods
__init__(objective[, next_message, ...])excluding(*field_names)Create a new AttackParameters subclass that excludes the specified fields.
from_seed_group_async(*, seed_group[, ...])Create an AttackParameters instance from a SeedAttackGroup.
Attributes
- classmethod excluding(*field_names: str) Type[AttackParameters][source]#
Create a new AttackParameters subclass that excludes the specified fields.
This factory method creates a frozen dataclass without the specified fields. The resulting class inherits the from_seed_group() behavior and will raise if excluded fields are passed as overrides.
- Parameters:
*field_names – Names of fields to exclude from the new params type.
- Returns:
A new AttackParameters subclass without the specified fields.
- Raises:
ValueError – If any field_name is not a valid field of this class.
Example
RolePlayAttackParameters = AttackParameters.excluding(“next_message”, “prepended_conversation”)
- async classmethod from_seed_group_async(*, seed_group: SeedAttackGroup, adversarial_chat: 'PromptChatTarget' | None = None, objective_scorer: 'TrueFalseScorer' | None = None, **overrides: Any) AttackParamsT[source]#
Create an AttackParameters instance from a SeedAttackGroup.
Extracts standard fields from the seed group and applies any overrides. If the seed_group has a simulated conversation config, generates the simulated conversation using the provided adversarial_chat and scorer.
- Parameters:
seed_group – The seed attack group to extract parameters from.
adversarial_chat – The adversarial chat target for generating simulated conversations. Required if seed_group has a simulated conversation config.
objective_scorer – The scorer for evaluating simulated conversations. Required if seed_group has a simulated conversation config.
**overrides – Field overrides to apply. Must be valid fields for this params type.
- Returns:
An instance of this AttackParameters type.
- Raises:
ValueError – If seed_group has no objective or if overrides contain invalid fields.
ValueError – If seed_group has simulated conversation but adversarial_chat/scorer not provided.