From 52da64a45b76f516b2a0354af93a2aa5b851eec3 Mon Sep 17 00:00:00 2001 From: yucheng Date: Mon, 14 Sep 2026 23:56:32 +0000 Subject: [PATCH] fix(guardrails): only cite message scoping in the not_run reason when scoping is on A request whose messages carry no scannable content at all, with no skip flag set, now records the neutral reason no scannable content instead of blaming configuration Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../openai/chat/guardrail_translation/handler.py | 6 +++++- .../test_openai_guardrail_handler.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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):