From b6e4e45a39d4360529257f083cc791ada8cfc1e4 Mon Sep 17 00:00:00 2001 From: Oliver Fei Date: Thu, 24 Sep 2026 15:29:02 -0400 Subject: [PATCH] fix(guardrails): remove unused TrendAI logging scan scope --- .../guardrail_hooks/trendai/__init__.py | 1 - .../guardrail_hooks/trendai/_models.py | 1 - .../guardrail_hooks/trendai/trendai.py | 7 ------ .../guardrail_hooks/trendai/test_trendai.py | 22 ++++--------------- 4 files changed, 4 insertions(+), 27 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/trendai/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/trendai/__init__.py index 27b2d1206f7..a506dab07bb 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/trendai/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/trendai/__init__.py @@ -31,7 +31,6 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail" timeout=settings.timeout, stream_overlap_size=settings.stream_overlap_size, response_content_chunk_size_bytes=settings.response_content_chunk_size_bytes, - logging_only_scan=settings.logging_only_scan, guardrail_name=guardrail_name, event_hook=_normalize_event_hook(litellm_params.mode), default_on=litellm_params.default_on is True, diff --git a/litellm/proxy/guardrails/guardrail_hooks/trendai/_models.py b/litellm/proxy/guardrails/guardrail_hooks/trendai/_models.py index b3ece6e2973..052d8e50630 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/trendai/_models.py +++ b/litellm/proxy/guardrails/guardrail_hooks/trendai/_models.py @@ -15,7 +15,6 @@ class TrendAISettings(BaseModel): timeout: float = 5.0 stream_overlap_size: int = 256 response_content_chunk_size_bytes: int = 49_500 - logging_only_scan: Literal["request", "response", "both"] = "both" class TrendAIChatMessage(BaseModel): diff --git a/litellm/proxy/guardrails/guardrail_hooks/trendai/trendai.py b/litellm/proxy/guardrails/guardrail_hooks/trendai/trendai.py index c55dfe1df58..d6ceea50f48 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/trendai/trendai.py +++ b/litellm/proxy/guardrails/guardrail_hooks/trendai/trendai.py @@ -80,7 +80,6 @@ class TrendAIGuardrail(CustomGuardrail): timeout: float = 5.0, stream_overlap_size: int = 256, response_content_chunk_size_bytes: int = RESPONSE_CONTENT_CHUNK_SIZE_BYTES, - logging_only_scan: Literal["request", "response", "both"] = "both", async_handler: _AsyncHTTPClient | None = None, guardrail_name: str | None = None, event_hook: GuardrailEventHooks | list[GuardrailEventHooks] | Mode | None = None, @@ -100,8 +99,6 @@ class TrendAIGuardrail(CustomGuardrail): ) if fallback_on_error not in ("block", "allow"): raise ValueError("fallback_on_error must be 'block' or 'allow'") - if logging_only_scan not in ("request", "response", "both"): - raise ValueError("logging_only_scan must be 'request', 'response', or 'both'") if timeout <= 0: raise ValueError("timeout must be greater than zero") if stream_overlap_size < 0: @@ -116,7 +113,6 @@ class TrendAIGuardrail(CustomGuardrail): self.timeout: float = timeout self.stream_overlap_size: int = stream_overlap_size self.response_content_chunk_size_bytes: int = response_content_chunk_size_bytes - self.logging_only_scan: Literal["request", "response", "both"] = logging_only_scan self.async_handler: _AsyncHTTPClient = async_handler or get_async_httpx_client( llm_provider=httpxSpecialProvider.GuardrailCallback ) @@ -137,9 +133,6 @@ class TrendAIGuardrail(CustomGuardrail): GuardrailEventHooks.logging_only, ] - def logging_only_scan_scope(self) -> Literal["request", "response", "both"]: - return self.logging_only_scan - @log_guardrail_information async def apply_guardrail( self, diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/trendai/test_trendai.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/trendai/test_trendai.py index a2b197da315..250bc30adbd 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/trendai/test_trendai.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/trendai/test_trendai.py @@ -37,7 +37,6 @@ def _guardrail( timeout: float = 5.0, stream_overlap_size: int = 256, response_content_chunk_size_bytes: int = 49_500, - logging_only_scan: Literal["request", "response", "both"] = "both", async_handler: httpx.AsyncClient | None = None, api_base: str = "https://guard.example.com/v3.0/aiSecurity", event_hook: GuardrailEventHooks = GuardrailEventHooks.pre_call, @@ -50,7 +49,6 @@ def _guardrail( timeout=timeout, stream_overlap_size=stream_overlap_size, response_content_chunk_size_bytes=response_content_chunk_size_bytes, - logging_only_scan=logging_only_scan, async_handler=async_handler, guardrail_name="trendai", event_hook=event_hook, @@ -538,29 +536,17 @@ def _logged_call(user_text: str, assistant_text: str) -> tuple[dict[str, object] @pytest.mark.asyncio -@pytest.mark.parametrize( - ("scope", "expected_scans"), - [ - ("request", ["user a@b.com"]), - ("response", ["assistant SECRET"]), - ("both", ["user a@b.com", "assistant SECRET"]), - ], -) -async def test_logging_only_scan_scope_selects_which_side_is_scanned( - scope: Literal["request", "response", "both"], expected_scans: Sequence[str] -) -> None: +async def test_logging_only_scans_both_sides_without_modifying_them() -> None: respond, scanned = _engine(redact={"a@b.com": "[EMAIL]", "SECRET": "******"}) async with httpx.AsyncClient(transport=httpx.MockTransport(respond)) as client: - guardrail = _guardrail( - async_handler=client, logging_only_scan=scope, event_hook=GuardrailEventHooks.logging_only - ) + guardrail = _guardrail(async_handler=client, event_hook=GuardrailEventHooks.logging_only) kwargs, response = _logged_call("user a@b.com", "assistant SECRET") out_kwargs, out_response = await guardrail.async_logging_hook(kwargs, response, CallTypes.acompletion.value) - assert scanned == list(expected_scans) + assert scanned == ["user a@b.com", "assistant SECRET"] assert out_kwargs["messages"] == [{"role": "user", "content": "user a@b.com"}] assert out_response is response assert response.choices[0].message.content == "assistant SECRET" entries = out_kwargs["standard_logging_object"]["guardrail_information"] - assert [entry["guardrail_status"] for entry in entries] == ["success"] * len(expected_scans) + assert [entry["guardrail_status"] for entry in entries] == ["success", "success"] assert all(entry["guardrail_mode"] == "logging_only" for entry in entries)