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): only cite message scoping in the not_run reason when scoping is on

yucheng52da64a45b76
diff --git a/litellm/llms/openai/chat/guardrail_translation/handler.py b/litellm/llms/openai/chat/guardrail_translation/handler.py
index 9d790aa71d4..0be4b6a3a20 100644
--- a/litellm/llms/openai/chat/guardrail_translation/handler.py
+++ b/litellm/llms/openai/chat/guardrail_translation/handler.py
@@ -212,7 +212,11 @@ class OpenAIChatCompletionsHandler(BaseTranslation):
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",
+ guardrail_json_response=(
+ "no scannable content after message scoping"
+ if skip_system or skip_tool or scan_only_tool_results
+ else "no scannable content"
+ ),
request_data=data,
guardrail_status="not_run",
)
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 5c971fe2c90..40dc5e2df2c 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
@@ -1917,6 +1917,21 @@ class TestNoScannableContentRecordsNotRun:
assert len(entries) == 1
assert entries[0]["guardrail_name"] == "skip-system-guardrail"
assert entries[0]["guardrail_status"] == "not_run"
+ assert entries[0]["guardrail_response"] == "no scannable content after message scoping"
+
+ @pytest.mark.asyncio
+ async def test_empty_content_without_scoping_does_not_blame_scoping(self):
+ handler = OpenAIChatCompletionsHandler()
+ guardrail = MockGuardrail(guardrail_name="unscoped-guardrail")
+ data = {"messages": [{"role": "user", "content": None}]}
+
+ await handler.process_input_messages(data=data, guardrail_to_apply=guardrail)
+
+ assert guardrail.last_inputs is None
+ entries = self._recorded_entries(data)
+ assert len(entries) == 1
+ assert entries[0]["guardrail_status"] == "not_run"
+ assert entries[0]["guardrail_response"] == "no scannable content"
@pytest.mark.asyncio
async def test_self_recording_guardrail_is_left_alone(self):