Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: revert presidio streaming type changes (unsafe cast)

Cursor Agenta9e45e70ea63
diff --git a/litellm/proxy/guardrails/guardrail_hooks/presidio.py b/litellm/proxy/guardrails/guardrail_hooks/presidio.py
index ce2419e97ca..5701f7dd9e8 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/presidio.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/presidio.py
@@ -1234,7 +1234,7 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
user_api_key_dict: UserAPIKeyAuth,
response: Any,
request_data: dict,
- ) -> AsyncGenerator[ModelResponseStream, None]:
+ ) -> AsyncGenerator[Union[ModelResponseStream, bytes], None]:
"""
Process streaming response chunks to unmask PII tokens when needed.
"""
@@ -1242,7 +1242,7 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
async for chunk in self._stream_apply_output_masking(
response, request_data
):
- yield cast(ModelResponseStream, chunk)
+ yield chunk
return
metadata = (request_data.get("metadata") or {}) if request_data else {}
@@ -1257,7 +1257,7 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
return
async for chunk in self._stream_pii_unmasking(response, request_data):
- yield cast(ModelResponseStream, chunk)
+ yield chunk
@staticmethod
def _preserve_usage_from_last_chunk(