test(logging): cover audio redaction via the custom logger entry path

Adds the regression test that reproduces the reported flow end to end: a custom logger with message_logging off receives a response whose audio field is nulled while the original response stays intact.
This commit is contained in:
dharaneesh 2026-09-14 10:47:34 +05:30
parent ff55f5dae0
commit bbec40fb72

View file

@ -16,6 +16,7 @@ from litellm.integrations.custom_logger import CustomLogger
from litellm.litellm_core_utils.redact_messages import (
_redact_responses_api_output,
perform_redaction,
redact_message_input_output_from_custom_logger,
redact_streaming_responses_for_custom_logger,
redacted_standard_logging_payload,
should_redact_message_logging,
@ -442,6 +443,33 @@ class TestPerformRedaction:
assert result.choices[0].message.audio is not None
assert result.choices[0].message.audio.transcript == "sensitive transcript"
def test_opted_out_logger_redacts_audio_on_custom_logger_entry(self):
logger = SimpleNamespace(message_logging=False)
logs = SimpleNamespace(model_call_details={})
response = litellm.ModelResponse(
id="resp-3",
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 = redact_message_input_output_from_custom_logger(logs, response, logger)
assert redacted.choices[0].message.audio is None
assert redacted.choices[0].message.content == "redacted-by-litellm"
assert response.choices[0].message.audio is not None
def test_redacts_audio_on_streaming_response_object(self):
streaming_choice = litellm.utils.StreamingChoices(
delta=litellm.utils.Delta(