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]

style: format code with black

Arshdeep Singh8364da014fe8
diff --git a/litellm/proxy/guardrails/guardrail_hooks/presidio.py b/litellm/proxy/guardrails/guardrail_hooks/presidio.py
index c3c6c3d2e03..78ade173bf9 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/presidio.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/presidio.py
@@ -402,10 +402,14 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
content_safety = data.get("content_safety", None)
verbose_proxy_logger.debug("content_safety: %s", content_safety)
presidio_config = self.get_presidio_settings_from_request_data(data)
- if call_type in [
- LitellmCallTypes.completion.value,
- LitellmCallTypes.acompletion.value,
- ] or call_type == "mcp_call":
+ if (
+ call_type
+ in [
+ LitellmCallTypes.completion.value,
+ LitellmCallTypes.acompletion.value,
+ ]
+ or call_type == "mcp_call"
+ ):
messages = data["messages"]
tasks = []
for m in messages:
diff --git a/litellm/types/guardrails.py b/litellm/types/guardrails.py
index 0c3dc662ec4..3f9f7cec0e0 100644
--- a/litellm/types/guardrails.py
+++ b/litellm/types/guardrails.py
@@ -40,7 +40,6 @@ class SupportedGuardrailIntegrations(Enum):
TOOL_PERMISSION = "tool_permission"
-
class Role(Enum):
SYSTEM = "system"
ASSISTANT = "assistant"
diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_presidio_union_fix.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_presidio_union_fix.py
index 549f715ed50..a062bc1a896 100644
--- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_presidio_union_fix.py
+++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_presidio_union_fix.py
@@ -17,42 +17,46 @@ class PiiAction(str, Enum):
def test_presidio_union_type_fix():
"""Test that Union[PiiEntityType, str] allows both enum and string entity types"""
-
+
# Custom recognizers for EMPLOYEE_ID and CUSTOMER_ID
custom_recognizers = [
{
"name": "Employee ID Recognizer",
"supported_language": "en",
- "patterns": [{"name": "employee id", "regex": "EMP-[0-9]{6}", "score": 0.9}],
+ "patterns": [
+ {"name": "employee id", "regex": "EMP-[0-9]{6}", "score": 0.9}
+ ],
"context": ["employee", "id"],
- "supported_entity": "EMPLOYEE_ID"
+ "supported_entity": "EMPLOYEE_ID",
},
{
"name": "Customer ID Recognizer",
"supported_language": "en",
- "patterns": [{"name": "customer id", "regex": "CUST-[0-9]{8}", "score": 0.9}],
+ "patterns": [
+ {"name": "customer id", "regex": "CUST-[0-9]{8}", "score": 0.9}
+ ],
"context": ["customer", "id"],
- "supported_entity": "CUSTOMER_ID"
- }
+ "supported_entity": "CUSTOMER_ID",
+ },
]
-
+
# This is the core fix - mixed entity types in pii_entities_config
pii_entities_config: Dict[Union[PiiEntityType, str], PiiAction] = {
PiiEntityType.EMAIL_ADDRESS: PiiAction.MASK,
"EMPLOYEE_ID": PiiAction.MASK,
"CUSTOMER_ID": PiiAction.BLOCK,
}
-
+
# Verify entities can be used together (what Presidio needs)
entities_list = list(pii_entities_config.keys())
assert len(entities_list) == 3
assert PiiEntityType.EMAIL_ADDRESS in entities_list
assert "EMPLOYEE_ID" in entities_list
assert "CUSTOMER_ID" in entities_list
-
+
print("✅ Union type fix verified: mixed entity types work correctly")
print("✅ Custom recognizers defined for EMPLOYEE_ID and CUSTOMER_ID")
if __name__ == "__main__":
- test_presidio_union_type_fix()
\ No newline at end of file
+ test_presidio_union_type_fix()