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 Presidio guardrail test TypeError and license base64 decoding error (#17538)

Alexsander Hamir96122a8b5ade
diff --git a/litellm/proxy/auth/litellm_license.py b/litellm/proxy/auth/litellm_license.py
index 80e08bde52c..6a8df823bc8 100644
--- a/litellm/proxy/auth/litellm_license.py
+++ b/litellm/proxy/auth/litellm_license.py
@@ -162,7 +162,12 @@ class LicenseCheck:
from litellm.proxy._types import EnterpriseLicenseData
- # Decode the license key
+ # Decode the license key - add padding if needed for base64
+ # Base64 strings need to be a multiple of 4 characters
+ padding_needed = len(license_key) % 4
+ if padding_needed:
+ license_key += "=" * (4 - padding_needed)
+
decoded = base64.b64decode(license_key)
message, signature = decoded.split(b".", 1)
diff --git a/tests/guardrails_tests/test_presidio_pii.py b/tests/guardrails_tests/test_presidio_pii.py
index e3f811ba7df..a1f6b7bfbbd 100644
--- a/tests/guardrails_tests/test_presidio_pii.py
+++ b/tests/guardrails_tests/test_presidio_pii.py
@@ -76,16 +76,20 @@ async def test_presidio_apply_guardrail():
presidio_anonymizer_api_base=os.environ.get("PRESIDIO_ANONYMIZER_API_BASE")
)
-
+ test_text = "My credit card number is 4111-1111-1111-1111 and my email is [email protected]"
response = await presidio_guardrail.apply_guardrail(
- text="My credit card number is 4111-1111-1111-1111 and my email is [email protected]",
- language="en",
+ inputs={"texts": [test_text]},
+ request_data={},
+ input_type="request",
)
print("response from apply guardrail for presidio: ", response)
- # assert tthe default config masks the credit card and email
- assert "4111-1111-1111-1111" not in response
- assert "[email protected]" not in response
+ # Extract the modified text from the response
+ modified_text = response["texts"][0] if response.get("texts") else ""
+
+ # assert the default config masks the credit card and email
+ assert "4111-1111-1111-1111" not in modified_text
+ assert "[email protected]" not in modified_text
@pytest.mark.asyncio
async def test_presidio_with_blocked_entities():