diff --git a/litellm/proxy/guardrails/guardrail_hooks/presidio.py b/litellm/proxy/guardrails/guardrail_hooks/presidio.py index 2a67bb93d57..2310295e95d 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/presidio.py +++ b/litellm/proxy/guardrails/guardrail_hooks/presidio.py @@ -121,9 +121,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail): # Loop-bound session cache for background threads self._loop_sessions: Dict[asyncio.AbstractEventLoop, aiohttp.ClientSession] = {} - # Result cache to avoid redundant network calls - self.pii_cache = DualCache() - if mock_testing is True: # for testing purposes only return @@ -488,13 +485,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail): """ Calls Presidio Analyze + Anonymize endpoints for PII Analysis + Masking """ - # Cache check - cache_key = f"presidio:pii:{text}:{output_parse_pii}:{presidio_config}:{self.pii_entities_config}" - cached_result = self.pii_cache.get_cache(cache_key) - if cached_result is not None: - verbose_proxy_logger.debug("PII Cache Hit for text: %s", text) - return cached_result - start_time = datetime.now() analyze_results: Optional[Union[List[PresidioAnalyzeResponseItem], Dict]] = None status: GuardrailStatus = "success" @@ -532,7 +522,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail): output_parse_pii=output_parse_pii, masked_entity_count=masked_entity_count, ) - self.pii_cache.set_cache(cache_key, anonymized_text) return anonymized_text return redacted_text["text"] except Exception as e: diff --git a/tests/test_presidio_latency.py b/tests/test_presidio_latency.py index 79c567e90ed..08d01fe78fb 100644 --- a/tests/test_presidio_latency.py +++ b/tests/test_presidio_latency.py @@ -97,43 +97,3 @@ async def test_optimization_presidio_avoid_recognizer_reloads_on_server(): # Optimization Check: payload should NOT contain the redundant recognizers assert "ad_hoc_recognizers" not in payload - -@pytest.mark.asyncio -async def test_optimization_presidio_pii_caching_skips_network_calls(): - """ - OPTIMIZATION VERIFICATION: - Verify that PII results are cached in local memory. - Identical text should return instantly from cache without making a - network round-trip to the Presidio service. - """ - presidio = _OPTIONAL_PresidioPIIMasking( - mock_testing=True, - presidio_analyzer_api_base="http://mock-analyzer", - presidio_anonymizer_api_base="http://mock-anonymizer" - ) - - # Mock network calls - presidio.analyze_text = MagicMock(return_value=asyncio.Future()) - presidio.analyze_text.return_value.set_result([]) - presidio.anonymize_text = MagicMock(return_value=asyncio.Future()) - presidio.anonymize_text.return_value.set_result("redacted text") - - # First call - Must hit the mock (Network) - result1 = await presidio.check_pii( - text="repetitive call center text", - output_parse_pii=False, - presidio_config=None, - request_data={} - ) - assert result1 == "redacted text" - assert presidio.analyze_text.call_count == 1 - - # Second call - Must hit the CACHE (No Network) - result2 = await presidio.check_pii( - text="repetitive call center text", - output_parse_pii=False, - presidio_config=None, - request_data={} - ) - assert result2 == "redacted text" - assert presidio.analyze_text.call_count == 1 # Counter should NOT increase