pyrit.prompt_converter.InsertPunctuationConverter#
- class InsertPunctuationConverter(word_swap_ratio: float = 0.2, between_words: bool = True)[source]#
Bases:
PromptConverterInserts punctuation into a prompt to test robustness.
Punctuation insertion: inserting single punctuations in string.punctuation. Words in a prompt: a word does not contain any punctuation and space. “a1b2c3” is a word; “a1 2” are 2 words; “a1,b,3” are 3 words.
- __init__(word_swap_ratio: float = 0.2, between_words: bool = True) None[source]#
Initialize the converter with a word swap ratio and punctuation insertion mode.
- Parameters:
- Raises:
ValueError – If
word_swap_ratiois not between 0 and 1.
Methods
__init__([word_swap_ratio, between_words])Initialize the converter with a word swap ratio and punctuation insertion mode.
convert_async(*, prompt[, input_type, ...])Convert the given prompt by inserting punctuation.
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.
Attributes
Tuple of input modalities supported by this converter.
Tuple of output modalities supported by this converter.
Common punctuation characters.
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', punctuation_list: List[str] | None = None) ConverterResult[source]#
Convert the given prompt by inserting punctuation.
- Parameters:
- Returns:
The result containing an iteration of modified prompts.
- Return type:
- Raises:
ValueError – If the input type is not supported.
- default_punctuation_list = [',', '.', '!', '?', ':', ';', '-']#
Common punctuation characters. Used if no punctuation list is provided.