diff --git a/litellm/litellm_core_utils/redact_messages.py b/litellm/litellm_core_utils/redact_messages.py index 9d22a5ddef5..0d46c18daf1 100644 --- a/litellm/litellm_core_utils/redact_messages.py +++ b/litellm/litellm_core_utils/redact_messages.py @@ -105,6 +105,8 @@ def _redact_choice_content(choice): choice.message.reasoning_content = REDACTED_BY_LITELLM if hasattr(choice.message, "thinking_blocks"): choice.message.thinking_blocks = None + if getattr(choice.message, "audio", None) is not None: + choice.message.audio = None _redact_tool_calls(getattr(choice.message, "tool_calls", None)) _redact_function_call(getattr(choice.message, "function_call", None)) elif isinstance(choice, litellm.utils.StreamingChoices): @@ -114,6 +116,8 @@ def _redact_choice_content(choice): choice.delta.reasoning_content = REDACTED_BY_LITELLM if hasattr(choice.delta, "thinking_blocks"): choice.delta.thinking_blocks = None + if getattr(choice.delta, "audio", None) is not None: + choice.delta.audio = None _redact_tool_calls(getattr(choice.delta, "tool_calls", None)) _redact_function_call(getattr(choice.delta, "function_call", None)) 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 584a3ac471c..38dff63e193 100644 --- a/tests/test_litellm/litellm_core_utils/test_redact_messages.py +++ b/tests/test_litellm/litellm_core_utils/test_redact_messages.py @@ -21,6 +21,7 @@ from litellm.litellm_core_utils.redact_messages import ( should_redact_message_logging, ) from litellm.responses.main import mock_responses_api_response +from litellm.types.utils import ChatCompletionAudioResponse @pytest.fixture(autouse=True) @@ -416,6 +417,55 @@ class TestPerformRedaction: '{"city": "sensitive-city"}' ) + def test_redacts_audio_on_model_response_object(self): + result = litellm.ModelResponse( + id="resp-2", + choices=[ + litellm.Choices( + message=litellm.Message( + content="message content", + role="assistant", + audio=ChatCompletionAudioResponse( + data="", + expires_at=1_752_000_000, + transcript="sensitive transcript", + ), + ) + ) + ], + model="gpt-4o-audio-preview", + ) + + redacted = perform_redaction({}, result) + + assert redacted.choices[0].message.audio is None + assert result.choices[0].message.audio is not None + assert result.choices[0].message.audio.transcript == "sensitive transcript" + + def test_redacts_audio_on_streaming_response_object(self): + streaming_choice = litellm.utils.StreamingChoices( + delta=litellm.utils.Delta( + content="delta content", + role="assistant", + audio=ChatCompletionAudioResponse( + data="", + expires_at=1_752_000_000, + transcript="sensitive transcript", + ), + ) + ) + streaming_response = SimpleNamespace(choices=[streaming_choice]) + details = { + "stream": True, + "complete_streaming_response": streaming_response, + } + + perform_redaction(details, None) + + delta = streaming_response.choices[0].delta + assert delta.audio is None + assert delta.content == "redacted-by-litellm" + def test_redacts_tool_call_arguments_on_streaming_response_object(self): """Reproduces the Stream=True path where tool calls arrive as deltas.""" streaming_choice = litellm.utils.StreamingChoices(