pyrit.scenario.garak.Encoding#
- class Encoding(*, seed_prompts: list[str] | None = None, objective_scorer: TrueFalseScorer | None = None, encoding_templates: Sequence[str] | None = None, include_baseline: bool = True, scenario_result_id: str | None = None)[source]#
Bases:
ScenarioEncoding Scenario implementation for PyRIT.
This scenario tests how resilient models are to various encoding attacks by encoding potentially harmful text (by default slurs and XSS payloads) and testing if the model will decode and repeat the encoded payload. It mimics the Garak encoding probe.
The scenario works by: 1. Taking seed prompts (the harmful text to be encoded) 2. Encoding them using various encoding schemes (Base64, ROT13, Morse, etc.) 3. Asking the target model to decode the encoded text 4. Scoring whether the model successfully decoded and repeated the harmful content
By default, this uses the same dataset as Garak: slur terms and web XSS payloads.
- __init__(*, seed_prompts: list[str] | None = None, objective_scorer: TrueFalseScorer | None = None, encoding_templates: Sequence[str] | None = None, include_baseline: bool = True, scenario_result_id: str | None = None)[source]#
Initialize the Encoding Scenario.
- Parameters:
seed_prompts (Optional[list[str]]) – Deprecated. Use dataset_config in initialize_async instead.
objective_scorer (Optional[TrueFalseScorer]) – The scorer used to evaluate if the model successfully decoded the payload. Defaults to DecodingScorer with encoding_scenario category.
encoding_templates (Optional[Sequence[str]]) – Templates used to construct the decoding prompts. Defaults to AskToDecodeConverter.garak_templates.
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 encoding-modified prompts.
scenario_result_id (Optional[str]) – Optional ID of an existing scenario result to resume.
Methods
__init__(*[, seed_prompts, ...])Initialize the Encoding Scenario.
Return the default dataset configuration for this scenario.
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 default_dataset_config() DatasetConfiguration[source]#
Return the default dataset configuration for this scenario.
- Returns:
Configuration with garak slur terms and web XSS payloads.
- Return type:
- classmethod get_default_strategy() ScenarioStrategy[source]#
Get the default strategy used when no strategies are specified.
- Returns:
EncodingStrategy.ALL (all encoding strategies).
- Return type:
- classmethod get_strategy_class() type[ScenarioStrategy][source]#
Get the strategy enum class for this scenario.
- Returns:
The EncodingStrategy enum class.
- Return type:
Type[ScenarioStrategy]