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(logging): redact standard logging choice metadata

userc52be31663e9
diff --git a/litellm/litellm_core_utils/redact_messages.py b/litellm/litellm_core_utils/redact_messages.py
index 1837ecb1170..dbc9cabdc7a 100644
--- a/litellm/litellm_core_utils/redact_messages.py
+++ b/litellm/litellm_core_utils/redact_messages.py
@@ -122,16 +122,7 @@ def _redact_standard_logging_object(model_call_details: dict):
elif isinstance(response, dict) and "choices" in response:
# ModelResponse dict format - redact content in choices
if isinstance(response.get("choices"), list):
- for choice in response["choices"]:
- if isinstance(choice, dict):
- if "message" in choice and isinstance(choice["message"], dict):
- choice["message"]["content"] = redacted_str
- if "audio" in choice["message"]:
- choice["message"]["audio"] = None
- elif "delta" in choice and isinstance(choice["delta"], dict):
- choice["delta"]["content"] = redacted_str
- if "audio" in choice["delta"]:
- choice["delta"]["audio"] = None
+ _redact_model_response_dict_choices(response["choices"], redacted_str)
elif isinstance(response, str):
standard_logging_object["response"] = redacted_str
else:
diff --git a/tests/test_litellm/litellm_core_utils/test_redact_messages.py b/tests/test_litellm/litellm_core_utils/test_redact_messages.py
index 1ba01ecd47d..60cfff6e4a0 100644
--- a/tests/test_litellm/litellm_core_utils/test_redact_messages.py
+++ b/tests/test_litellm/litellm_core_utils/test_redact_messages.py
@@ -258,6 +258,47 @@ class TestPerformRedaction:
assert delta["thinking_blocks"] is None
assert delta["audio"] is None
+ def test_redacts_standard_logging_model_response_dict_choices(self):
+ details = {
+ "standard_logging_object": {
+ "response": {
+ "choices": [
+ {
+ "message": {
+ "content": "message content",
+ "reasoning_content": "message reasoning",
+ "thinking_blocks": ["thinking"],
+ "audio": {"data": "audio"},
+ }
+ },
+ {
+ "delta": {
+ "content": "delta content",
+ "reasoning_content": "delta reasoning",
+ "thinking_blocks": ["delta thinking"],
+ "audio": {"data": "audio"},
+ }
+ },
+ ]
+ }
+ }
+ }
+
+ perform_redaction(details, None)
+
+ choices = details["standard_logging_object"]["response"]["choices"]
+ message = choices[0]["message"]
+ assert message["content"] == "redacted-by-litellm"
+ assert message["reasoning_content"] == "redacted-by-litellm"
+ assert message["thinking_blocks"] is None
+ assert message["audio"] is None
+
+ delta = choices[1]["delta"]
+ assert delta["content"] == "redacted-by-litellm"
+ assert delta["reasoning_content"] == "redacted-by-litellm"
+ assert delta["thinking_blocks"] is None
+ assert delta["audio"] is None
+
def test_redacts_object_choices_inside_model_response_dict(self):
result = {
"choices": [