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:
source_package – The package to use for homoglyph generation. Can be either “confusable_homoglyphs” which can be found here: https://pypi.org/project/confusable-homoglyphs/ or “confusables” which can be found here: https://pypi.org/project/confusables/. “Confusable_homoglyphs” is used by default as it is more regularly maintained and up to date with the latest Unicode-provided confusables found here: https://www.unicode.org/Public/security/latest/confusables.txt. However, “confusables” provides additional methods of matching characters (not just Unicode list), so each character has more possible substitutions.
deterministic – This argument is for unittesting only.
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:
- Returns:
The result containing the prompt with confusable subsitutions applied.
- Return type: