fix(logging): redact audio output from message logging

Custom loggers that opt out of message logging still received the full assistant audio transcript and base64 payload. perform_redaction redacts choice.message and choice.delta content, reasoning, thinking blocks and tool calls but never nulled the audio field, while the dict-form redaction path already did. Object-form redaction now matches the dict form and closes the transcript leak on both the standard and streaming response paths.
This commit is contained in:
dharaneesh 2026-09-14 10:27:20 +05:30
parent 30f33a949b
commit ff55f5dae0
2 changed files with 54 additions and 0 deletions

View file

@ -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))

View file

@ -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="<base64-audio>",
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="<base64-audio>",
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(