From c38dda2b2f47cd7e1056f077b8943f598c26cd21 Mon Sep 17 00:00:00 2001 From: yucheng Date: Sat, 19 Sep 2026 17:57:47 +0000 Subject: [PATCH] fix(llmguard): drop call types the proxy never routes through moderation Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../enterprise_callbacks/llm_guard.py | 5 ---- .../enterprise_callbacks/test_llm_guard.py | 23 +++++++++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py b/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py index 1559fff291c..3422e8969b0 100644 --- a/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py +++ b/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py @@ -147,11 +147,6 @@ class _ENTERPRISE_LLMGuard(CustomLogger): "aembedding", "image_generation", "aimage_generation", - "moderation", - "amoderation", - "audio_transcription", - "transcription", - "atranscription", ) if call_type not in accepted_call_types: self.print_verbose( diff --git a/tests/test_litellm/enterprise/enterprise_callbacks/test_llm_guard.py b/tests/test_litellm/enterprise/enterprise_callbacks/test_llm_guard.py index 4bb663b3bf0..5695b184479 100644 --- a/tests/test_litellm/enterprise/enterprise_callbacks/test_llm_guard.py +++ b/tests/test_litellm/enterprise/enterprise_callbacks/test_llm_guard.py @@ -20,13 +20,8 @@ from litellm.types.utils import CallTypesLiteral ("embeddings", "input"), ("embedding", "input"), ("aembedding", "input"), - ("moderation", "input"), - ("amoderation", "input"), ("image_generation", "prompt"), ("aimage_generation", "prompt"), - ("audio_transcription", "prompt"), - ("transcription", "prompt"), - ("atranscription", "prompt"), ), ) @pytest.mark.parametrize("is_valid", (True, False)) @@ -68,6 +63,24 @@ async def test_llm_guard_call_type_aliases( ) +@pytest.mark.parametrize("call_type", ("amoderation", "atranscription", "aresponses", "aanthropic_messages")) +@pytest.mark.asyncio +async def test_llm_guard_ignores_call_types_the_proxy_never_moderates( + call_type: CallTypesLiteral, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(litellm, "llm_guard_mode", "all") + llm_guard: Final = _ENTERPRISE_LLMGuard( + mock_testing=True, + mock_redacted_text={"sanitized_prompt": "[REDACTED]", "is_valid": False}, + ) + data: Final = {"input": "email: person@example.com"} + result: Final = await llm_guard.async_moderation_hook( + data=data, user_api_key_dict=UserAPIKeyAuth(), call_type=call_type + ) + assert result is data + assert data["input"] == "email: person@example.com" + + @pytest.mark.parametrize("call_type", ("text_completion", "atext_completion")) @pytest.mark.parametrize("is_valid", (True, False)) @pytest.mark.asyncio