Skip to content

Commit a6c3fb0

Browse files
authored
FIX: support moderation errors for MAI image models (#1890)
1 parent f43855b commit a6c3fb0

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

pyrit/prompt_target/openai/openai_error_handling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _is_content_filter_error(data: Union[dict[str, object], str]) -> bool:
7575
# Check for explicit content_filter or moderation_blocked codes
7676
error_obj = data.get("error")
7777
code = error_obj.get("code") if isinstance(error_obj, dict) else None # type: ignore[ty:invalid-argument-type]
78-
if code in ["content_filter", "moderation_blocked"]:
78+
if code in ["content_filter", "content_safety_violation", "moderation_blocked"]:
7979
return True
8080
# OpenAI uses "invalid_prompt" for model-level safety blocks (e.g. CBRN topics).
8181
# Only treat it as a content filter when the message indicates a safety block,

pyrit/prompt_target/openai/openai_image_target.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ async def _send_edit_request_async(self, message: Message) -> Message:
299299
# Construct request parameters for image editing
300300
image_edit_args: dict[str, Any] = {
301301
"model": self._model_name,
302-
# Single image can be sent (and MUST BE in MAI models) as a tuple, multiple images must be a list
302+
# Single image sent as a tuple (mandatory for targets that support only one image input such as MAI,
303+
# also supported by other targets such as OpenAI). Multiple images always sent as a list.
303304
"image": image_files[0] if len(image_files) == 1 else image_files,
304305
"prompt": text_prompt,
305306
"size": self.image_size,

0 commit comments

Comments
 (0)