pyrit.prompt_converter.VariationConverter#

class VariationConverter(*, converter_target: PromptChatTarget = REQUIRED_VALUE, prompt_template: SeedPrompt | None = None)[source]#

Bases: PromptConverter

Generates variations of the input prompts using the converter target.

__init__(*, converter_target: PromptChatTarget = REQUIRED_VALUE, prompt_template: SeedPrompt | None = None)[source]#

Initialize the converter with the specified target and prompt template.

Parameters:
  • converter_target (PromptChatTarget) – The target to which the prompt will be sent for conversion. Can be omitted if a default has been configured via PyRIT initialization.

  • prompt_template (SeedPrompt, optional) – The template used for generating the system prompt. If not provided, a default template will be used.

Raises:

ValueError – If converter_target is not provided and no default has been configured.

Methods

__init__(*[, converter_target, prompt_template])

Initialize the converter with the specified target and prompt template.

convert_async(*, prompt[, input_type])

Convert the given prompt by generating variations of it using the converter target.

convert_tokens_async(*, prompt[, ...])

Convert substrings within a prompt that are enclosed by specified start and end tokens.

get_identifier()

Return an identifier dictionary for the converter.

input_supported(input_type)

Check if the input type is supported by the converter.

output_supported(output_type)

Check if the output type is supported by the converter.

send_variation_prompt_async(request)

Send the message to the converter target and retrieve the response.

Attributes

SUPPORTED_INPUT_TYPES

Tuple of input modalities supported by this converter.

SUPPORTED_OUTPUT_TYPES

Tuple of output modalities supported by this converter.

supported_input_types

Returns a list of supported input types for the converter.

supported_output_types

Returns 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 by generating variations of it using the converter target.

Parameters:
  • prompt (str) – The prompt to be converted.

  • input_type (PromptDataType) – The type of input data.

Returns:

The result containing the generated variations.

Return type:

ConverterResult

Raises:

ValueError – If the input type is not supported.

async send_variation_prompt_async(request: Message) str[source]#

Send the message to the converter target and retrieve the response.

Parameters:

request (Message) – The message to be sent to the converter target.

Returns:

The response message from the converter target.

Return type:

str

Raises:

InvalidJsonException – If the response is not valid JSON or does not contain the expected keys.