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
[Fix] - SensitiveDataMasker converts lists to string (#15420)
Alexsander Hamir9d7dea42d0b7
diff --git a/litellm/litellm_core_utils/sensitive_data_masker.py b/litellm/litellm_core_utils/sensitive_data_masker.pyindex 05f1a37ca12..ea0bed30416 100644--- a/litellm/litellm_core_utils/sensitive_data_masker.py+++ b/litellm/litellm_core_utils/sensitive_data_masker.py@@ -75,7 +75,7 @@ class SensitiveDataMasker:masked_data[k] = self._mask_value(str_value)else:masked_data[k] = (- v if isinstance(v, (int, float, bool, str)) else str(v)+ v if isinstance(v, (int, float, bool, str, list)) else str(v))except Exception:masked_data[k] = "<unable to serialize>"@@ -89,12 +89,14 @@ masker = SensitiveDataMasker()data = {"api_key": "sk-1234567890abcdef","redis_password": "very_secret_pass",- "port": 6379+ "port": 6379,+ "tags": ["East US 2", "production", "test"]}masked = masker.mask_dict(data)# Result: {# "api_key": "sk-1****cdef",# "redis_password": "very****pass",-# "port": 6379+# "port": 6379,+# "tags": ["East US 2", "production", "test"]# }"""diff --git a/tests/test_litellm/litellm_core_utils/test_sensitive_data_masker.py b/tests/test_litellm/litellm_core_utils/test_sensitive_data_masker.pynew file mode 100644index 00000000000..6356c5137b8--- /dev/null+++ b/tests/test_litellm/litellm_core_utils/test_sensitive_data_masker.py@@ -0,0 +1,31 @@+"""+Unit tests for SensitiveDataMasker - List Preservation+"""++import os+import sys++import pytest++# Add the parent directory to the system path+sys.path.insert(0, os.path.abspath("../../.."))++from litellm.litellm_core_utils.sensitive_data_masker import SensitiveDataMasker+++def test_lists_are_preserved_not_converted_to_strings():+ """+ Regression test: Ensure lists are preserved as JSON arrays, not converted to strings.+ Previously, tags field in /model/info was returned as "['tag1', 'tag2']" instead of ["tag1", "tag2"]+ """+ masker = SensitiveDataMasker()++ data = {+ "tags": ["East US 2", "production", "test"],+ }++ masked = masker.mask_dict(data)++ # Must be a list, not a string+ assert isinstance(masked["tags"], list)+ assert masked["tags"] == ["East US 2", "production", "test"]