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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
merge: resolve conflict with upstream/main in presidio.py
Chesarsec16bd3509dc
diff --cc litellm/proxy/guardrails/guardrail_hooks/presidio.pyindex 67868155834,6f50099b516..ce32ebf54f8--- a/litellm/proxy/guardrails/guardrail_hooks/presidio.py+++ b/litellm/proxy/guardrails/guardrail_hooks/presidio.py@@@ -55,7 -55,7 +55,7 @@@ from litellm.types.proxy.guardrails.guaPresidioAnalyzeRequest,PresidioAnalyzeResponseItem,)--from litellm.types.utils import GuardrailStatus++from litellm.types.utils import GuardrailStatus, StreamingChoicesfrom litellm.utils import (EmbeddingResponse,ImageResponse,@@@ -910,13 -971,75 +970,74 @@@ class _OPTIONAL_PresidioPIIMasking(Custtext_value = item.get("text")if text_value is None:continue- item["text"] = await self.check_pii(- text=text_value,- output_parse_pii=False,- presidio_config=presidio_config,- request_data=request_data,- )+ if mode == "unmask":+ item["text"] = self._unmask_pii_text(text_value, pii_tokens)+ elif mode == "mask":+ item["text"] = await self.check_pii(+ text=text_value,+ output_parse_pii=False,+ presidio_config=presidio_config,+ request_data=request_data,+ )++ # 2. Process tool calls+ tool_calls = getattr(message, "tool_calls", None)+ if tool_calls:+ for tool_call in tool_calls:+ function = getattr(tool_call, "function", None)+ if function and hasattr(function, "arguments"):+ args = function.arguments+ if isinstance(args, str):+ if mode == "unmask":+ function.arguments = self._unmask_pii_text(+ args, pii_tokens+ )+ elif mode == "mask":+ function.arguments = await self.check_pii(+ text=args,+ output_parse_pii=False,+ presidio_config=presidio_config,+ request_data=request_data,+ )++ # 3. Process legacy function calls+ function_call = getattr(message, "function_call", None)+ if function_call and hasattr(function_call, "arguments"):+ args = function_call.arguments+ if isinstance(args, str):+ if mode == "unmask":+ function_call.arguments = self._unmask_pii_text(+ args, pii_tokens+ )+ elif mode == "mask":+ function_call.arguments = await self.check_pii(+ text=args,+ output_parse_pii=False,+ presidio_config=presidio_config,+ request_data=request_data,+ )-+ return response++ async def _mask_output_response(+ self,+ response: Union[ModelResponse, EmbeddingResponse, ImageResponse],+ request_data: dict,+ ):+ """+ Apply Presidio masking on model responses (non-streaming).+ """+ if not isinstance(response, ModelResponse):+ return response++ # skip streaming here; handled in async_post_call_streaming_iterator_hook- if response.choices and isinstance(response.choices[0], StreamingChoices):++ if isinstance(response, ModelResponseStream):+ return response+ await self._process_response_for_pii(+ response=response,+ request_data=request_data,+ mode="mask",+ )return responseasync def async_post_call_streaming_iterator_hook(