Source code for pyrit.prompt_converter.character_space_converter

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import re

from pyrit.models import PromptDataType
from pyrit.prompt_converter import PromptConverter, ConverterResult


[docs] class CharacterSpaceConverter(PromptConverter):
[docs] async def convert_async(self, *, prompt: str, input_type: PromptDataType = "text") -> ConverterResult: """ Simple converter that spaces out the input prompt and removes specified punctuations. For more information on the bypass strategy, refer to: https://www.robustintelligence.com/blog-posts/bypassing-metas-llama-classifier-a-simple-jailbreak """ if not self.input_supported(input_type): raise ValueError("Input type not supported") converted_text = re.sub("[!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~]", "", " ".join(prompt)) return ConverterResult(output_text=converted_text, output_type="text")
[docs] def input_supported(self, input_type: PromptDataType) -> bool: return input_type == "text"