pyrit.prompt_converter.AnsiAttackConverter#
- class AnsiAttackConverter(include_raw: bool = True, include_escaped: bool = True, include_tasks: bool = True, include_repeats: bool = True, include_unescape: bool = True, incorporate_user_prompt: bool = True)[source]#
Bases:
PromptConverterGenerates prompts with ANSI codes to evaluate LLM behavior and system risks.
- This converter can:
Use raw and escaped ANSI payloads.
Ask the model about ANSI codes, repeat given payloads, unescape strings.
Incorporate the user’s original prompt into the final scenario, making the testing more dynamic.
- __init__(include_raw: bool = True, include_escaped: bool = True, include_tasks: bool = True, include_repeats: bool = True, include_unescape: bool = True, incorporate_user_prompt: bool = True)[source]#
Initialize the converter with various options to control the scenarios generated.
- Parameters:
include_raw (bool) – Include scenarios with raw ANSI codes.
include_escaped (bool) – Include scenarios with escaped ANSI codes.
include_tasks (bool) – Include “ASKS + HIGH_LEVEL_TASKS” scenarios.
include_repeats (bool) – Include “repeat this payload” scenarios.
include_unescape (bool) – Include “unescape this payload” scenarios.
incorporate_user_prompt (bool) – If True, the user’s prompt is integrated into the final scenario.
Methods
__init__([include_raw, include_escaped, ...])Initialize the converter with various options to control the scenarios generated.
convert_async(*, prompt[, input_type])Convert the given prompt into an ANSI attack scenario.
convert_tokens_async(*, prompt[, ...])Convert substrings within a prompt that are enclosed by specified start and end tokens.
get_identifier()Get the typed identifier for this object.
input_supported(input_type)Check if the input type is supported.
output_supported(output_type)Check if the output type is supported.
Attributes
Tuple of input modalities supported by this converter.
Tuple of output modalities supported by this converter.
supported_input_typesReturns a list of supported input types for the converter.
supported_output_typesReturns a list of supported output types for the converter.
- SUPPORTED_INPUT_TYPES: tuple[Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'], ...] = ('text',)#
Tuple of input modalities supported by this converter. Subclasses must override this.
- SUPPORTED_OUTPUT_TYPES: tuple[Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'], ...] = ('text',)#
Tuple of output modalities supported by this converter. Subclasses must override this.
- async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] = 'text') ConverterResult[source]#
Convert the given prompt into an ANSI attack scenario.
- Parameters:
prompt (str) – The original user prompt.
input_type (PromptDataType) – The type of input data.
- Returns:
The result containing the generated ANSI scenario prompt.
- Return type:
- Raises:
ValueError – If the input type is not supported.
- input_supported(input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output']) bool[source]#
Check if the input type is supported.
- Parameters:
input_type (PromptDataType) – The type of input data.
- Returns:
True if the input type is supported, False otherwise.
- Return type:
- output_supported(output_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output']) bool[source]#
Check if the output type is supported.
- Parameters:
output_type (PromptDataType) – The type of output data.
- Returns:
True if the output type is supported, False otherwise.
- Return type: