pyrit.prompt_converter.RandomTranslationConverter#

class RandomTranslationConverter(*, converter_target: PromptChatTarget = REQUIRED_VALUE, system_prompt_template: SeedPrompt | None = None, languages: List[str] | None = None, word_selection_strategy: WordSelectionStrategy | None = None)[source]#

Bases: LLMGenericTextConverter, WordLevelConverter

Translates each individual word in a prompt to a random language using an LLM.

An existing PromptChatTarget is used to perform the translation (like Azure OpenAI).

__init__(*, converter_target: PromptChatTarget = REQUIRED_VALUE, system_prompt_template: SeedPrompt | None = None, languages: List[str] | None = None, word_selection_strategy: WordSelectionStrategy | None = None)[source]#

Initialize the converter with a target, an optional system prompt template, and language options.

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

  • system_prompt_template (Optional[SeedPrompt]) – The system prompt template to use for the conversion. If not provided, a default template will be used.

  • languages (Optional[List[str]]) – The list of available languages to use for translation.

  • word_selection_strategy (Optional[WordSelectionStrategy]) – Strategy for selecting which words to convert. If None, all words will be converted.

Raises:

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

Methods

__init__(*[, converter_target, ...])

Initialize the converter with a target, an optional system prompt template, and language options.

convert_async(*, prompt[, input_type])

Convert the given prompt into the target format supported by the converter.

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

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

convert_word_async(word)

Convert a single word into the target format supported by the converter.

get_identifier()

Return an identifier dictionary for the converter.

input_supported(input_type)

Check if the input type is supported by the converter.

join_words(words)

Provide a way for subclasses to override the default behavior of joining words.

output_supported(output_type)

Check if the output type is supported by the converter.

validate_input(prompt)

Validate the input before processing (can be overridden by subclasses).

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 into the target format supported by the converter.

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

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

Returns:

The result containing the converted output and its type.

Return type:

ConverterResult

async convert_word_async(word: str) str[source]#

Convert a single word into the target format supported by the converter.

Parameters:

word (str) – The word to be converted.

Returns:

The converted word.

Return type:

str