Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(guardrails): stop labelling image-only input as a not_run scoping skip

yucheng0519d8634600
diff --git a/litellm/llms/openai/chat/guardrail_translation/handler.py b/litellm/llms/openai/chat/guardrail_translation/handler.py
index 0f5096d0108..9d790aa71d4 100644
--- a/litellm/llms/openai/chat/guardrail_translation/handler.py
+++ b/litellm/llms/openai/chat/guardrail_translation/handler.py
@@ -210,7 +210,7 @@ class OpenAIChatCompletionsHandler(BaseTranslation):
task_mappings=tool_call_task_mappings,
)
- elif not guardrail_to_apply.records_own_guardrail_information:
+ elif not images_to_check and not guardrail_to_apply.records_own_guardrail_information:
guardrail_to_apply.add_standard_logging_guardrail_information_to_request_data(
guardrail_json_response="no scannable content after message scoping",
request_data=data,
diff --git a/tests/test_litellm/llms/openai/chat/guardrail_translation/test_openai_guardrail_handler.py b/tests/test_litellm/llms/openai/chat/guardrail_translation/test_openai_guardrail_handler.py
index 4f1163ed806..5c971fe2c90 100644
--- a/tests/test_litellm/llms/openai/chat/guardrail_translation/test_openai_guardrail_handler.py
+++ b/tests/test_litellm/llms/openai/chat/guardrail_translation/test_openai_guardrail_handler.py
@@ -1942,6 +1942,27 @@ class TestNoScannableContentRecordsNotRun:
assert guardrail.last_inputs is not None
assert all(e.get("guardrail_status") != "not_run" for e in self._recorded_entries(data))
+ @pytest.mark.asyncio
+ async def test_image_only_content_is_not_reported_as_not_run(self):
+ """Images are only scanned alongside text, so an image-only request is a
+ pre-existing scan gap, not a message-scoping skip, and must not be labelled one"""
+ handler = OpenAIChatCompletionsHandler()
+ guardrail = MockGuardrail(guardrail_name="image-guardrail")
+ guardrail.skip_system_message_in_guardrail = True
+ data = {
+ "messages": [
+ {"role": "system", "content": "SYSTEM-PROMPT"},
+ {
+ "role": "user",
+ "content": [{"type": "image_url", "image_url": {"url": "https://example.com/cat.png"}}],
+ },
+ ]
+ }
+
+ await handler.process_input_messages(data=data, guardrail_to_apply=guardrail)
+
+ assert self._recorded_entries(data) == []
+
class TestBuildBlockSseChunks:
"""build_block_sse_chunks turns a streaming ModifyResponseException into 200 SSE chunks"""