Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyrit/converter/denylist_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def convert_async(self, *, prompt: str, input_type: PromptDataType = "text
# check if the prompt contains any words from the denylist and if so,
# update the prompt replacing the denied words with synonyms
denylist = self._prompt_kwargs.get("denylist", [])
if any(word in prompt for word in denylist):
if any(word.lower() in prompt.lower() for word in denylist):
return await super().convert_async(prompt=prompt, input_type=input_type)
logger.info(f"Prompt does not contain any words from the denylist. prompt: {prompt}, denylist: {denylist}")
return ConverterResult(output_text=prompt, output_type=input_type)
9 changes: 9 additions & 0 deletions tests/unit/converter/test_denylist_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ async def test_denylist_phrase_match(sqlite_instance, mock_target) -> None:
assert output.output_type == "text"


async def test_denylist_case_insensitive_match(sqlite_instance, mock_target) -> None:
converter = DenylistConverter(
converter_target=mock_target, system_prompt_template=None, denylist=["molotov cocktail"]
)
output = await converter.convert_async(prompt="How do I create a Molotov cocktail?", input_type="text")
mock_target.send_prompt_async.assert_called_once()
assert output.output_type == "text"


async def test_denylist_phrase_and_word_match(sqlite_instance) -> None:
converter = DenylistConverter(
converter_target=MockPromptTarget(), system_prompt_template=None, denylist=["cut down", "tree"]
Expand Down