pyrit.prompt_converter.UnicodeConfusableConverter#

class UnicodeConfusableConverter(*, source_package: Literal['confusable_homoglyphs', 'confusables'] = 'confusable_homoglyphs', deterministic: bool = False)[source]#

Bases: PromptConverter

A PromptConverter that applies substitutions to words in the prompt to test adversarial textual robustness by replacing characters with visually similar ones.

__init__(*, source_package: Literal['confusable_homoglyphs', 'confusables'] = 'confusable_homoglyphs', deterministic: bool = False)[source]#

Initializes the UnicodeConfusableConverter.

Parameters:

Methods

__init__(*[, source_package, deterministic])

Initializes the UnicodeConfusableConverter.

convert_async(*, prompt[, input_type])

Converts the given prompt by applying confusable substitutions.

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

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

get_identifier()

input_supported(input_type)

Checks if the input type is supported by the converter

async convert_async(*, prompt: str, input_type='text') ConverterResult[source]#

Converts the given prompt by applying confusable substitutions. This leads to a prompt that looks similar, but is actually different (e.g., replacing a Latin ‘a’ with a Cyrillic ‘а’).

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

  • input_type (str) – The type of input (should be “text”).

Returns:

The result containing the prompt with confusable subsitutions applied.

Return type:

ConverterResult

input_supported(input_type: Literal['text', 'image_path', 'audio_path', 'url', 'error']) bool[source]#

Checks if the input type is supported by the converter

Parameters:

input_type – The input type to check

Returns:

True if the input type is supported, False otherwise

Return type:

bool