From dd05ae2748049f40f614c3d8667c4742e07b7312 Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Wed, 28 Jan 2026 16:01:47 -0800 Subject: [PATCH] Remove reduntant solution --- .../guardrails/guardrail_hooks/presidio.py | 9 +----- tests/test_presidio_latency.py | 28 +------------------ 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/presidio.py b/litellm/proxy/guardrails/guardrail_hooks/presidio.py index 2310295e95d..71ad9819146 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/presidio.py +++ b/litellm/proxy/guardrails/guardrail_hooks/presidio.py @@ -84,7 +84,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail): presidio_score_thresholds: Optional[ Dict[Union[PiiEntityType, str], float] ] = None, - presidio_ad_hoc_recognizers_on_server: Optional[bool] = None, **kwargs, ): if logging_only is True: @@ -105,9 +104,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail): presidio_score_thresholds or {} ) self.presidio_language = presidio_language or "en" - self.presidio_ad_hoc_recognizers_on_server = ( - presidio_ad_hoc_recognizers_on_server or False - ) # Shared HTTP session to prevent memory leaks (issue #14540) self._http_session: Optional[aiohttp.ClientSession] = None # Lock to prevent race conditions when creating session under concurrent load @@ -251,10 +247,7 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail): ################################################################## ###### Check if user has configured any params for this guardrail ################################################################ - if ( - self.ad_hoc_recognizers is not None - and self.presidio_ad_hoc_recognizers_on_server is False - ): + if self.ad_hoc_recognizers is not None: analyze_payload["ad_hoc_recognizers"] = self.ad_hoc_recognizers if self.pii_entities_config: diff --git a/tests/test_presidio_latency.py b/tests/test_presidio_latency.py index 08d01fe78fb..d434e6222eb 100644 --- a/tests/test_presidio_latency.py +++ b/tests/test_presidio_latency.py @@ -70,30 +70,4 @@ async def test_bug_presidio_session_explosion_background_thread_causes_latency() # FIX VERIFICATION: Should now be 1 session (reused) instead of 10. assert session_creations == 1 - await presidio._close_http_session() - -@pytest.mark.asyncio -async def test_optimization_presidio_avoid_recognizer_reloads_on_server(): - """ - OPTIMIZATION VERIFICATION: - Verify that ad_hoc_recognizers are OMITTED from the payload when - presidio_ad_hoc_recognizers_on_server is True. - Sending them on every request forces the Presidio server to reload its - entire registry, spiking CPU and latency. - """ - presidio = _OPTIONAL_PresidioPIIMasking( - mock_testing=True, - presidio_analyzer_api_base="http://mock-analyzer", - presidio_anonymizer_api_base="http://mock-anonymizer", - presidio_ad_hoc_recognizers_on_server=True - ) - presidio.ad_hoc_recognizers = [{"name": "CustomRecognizer", "supported_entity": "CUSTOM"}] - - payload = presidio._get_presidio_analyze_request_payload( - text="some text", - presidio_config=None, - request_data={} - ) - - # Optimization Check: payload should NOT contain the redundant recognizers - assert "ad_hoc_recognizers" not in payload + await presidio._close_http_session() \ No newline at end of file