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: Redact reasoning summaries in ResponsesAPI output when message logging is disabled (#15965)
Sameer Kankute8f2becd1c432
diff --git a/litellm/litellm_core_utils/redact_messages.py b/litellm/litellm_core_utils/redact_messages.pyindex 4237f005465..849cb20cdc5 100644--- a/litellm/litellm_core_utils/redact_messages.py+++ b/litellm/litellm_core_utils/redact_messages.py@@ -40,6 +40,38 @@ def redact_message_input_output_from_custom_logger(return result+def _redact_choice_content(choice):+ """Helper to redact content in a choice (message or delta)."""+ if isinstance(choice, litellm.Choices):+ choice.message.content = "redacted-by-litellm"+ if hasattr(choice.message, "reasoning_content"):+ choice.message.reasoning_content = "redacted-by-litellm"+ if hasattr(choice.message, "thinking_blocks"):+ choice.message.thinking_blocks = None+ elif isinstance(choice, litellm.utils.StreamingChoices):+ choice.delta.content = "redacted-by-litellm"+ if hasattr(choice.delta, "reasoning_content"):+ choice.delta.reasoning_content = "redacted-by-litellm"+ if hasattr(choice.delta, "thinking_blocks"):+ choice.delta.thinking_blocks = None+++def _redact_responses_api_output(output_items):+ """Helper to redact ResponsesAPIResponse output items."""+ for output_item in output_items:+ if hasattr(output_item, "content") and isinstance(output_item.content, list):+ for content_part in output_item.content:+ if hasattr(content_part, "text"):+ content_part.text = "redacted-by-litellm"++ # Redact reasoning items in output array+ if hasattr(output_item, "type") and output_item.type == "reasoning":+ if hasattr(output_item, "summary") and isinstance(output_item.summary, list):+ for summary_item in output_item.summary:+ if hasattr(summary_item, "text"):+ summary_item.text = "redacted-by-litellm"++def perform_redaction(model_call_details: dict, result):"""Performs the actual redaction on the logging object and result.@@ -59,19 +91,12 @@ def perform_redaction(model_call_details: dict, result):_streaming_response = model_call_details["complete_streaming_response"]if hasattr(_streaming_response, "choices"):for choice in _streaming_response.choices:- if isinstance(choice, litellm.Choices):- choice.message.content = "redacted-by-litellm"- elif isinstance(choice, litellm.utils.StreamingChoices):- choice.delta.content = "redacted-by-litellm"+ _redact_choice_content(choice)elif hasattr(_streaming_response, "output"):- # Handle ResponsesAPIResponse format- for output_item in _streaming_response.output:- if hasattr(output_item, "content") and isinstance(- output_item.content, list- ):- for content_part in output_item.content:- if hasattr(content_part, "text"):- content_part.text = "redacted-by-litellm"+ _redact_responses_api_output(_streaming_response.output)+ # Redact reasoning field in ResponsesAPIResponse+ if hasattr(_streaming_response, "reasoning") and _streaming_response.reasoning is not None:+ _streaming_response.reasoning = None# Redact resultif result is not None:@@ -87,17 +112,13 @@ def perform_redaction(model_call_details: dict, result):if isinstance(_result, litellm.ModelResponse):if hasattr(_result, "choices") and _result.choices is not None:for choice in _result.choices:- if isinstance(choice, litellm.Choices):- choice.message.content = "redacted-by-litellm"- elif isinstance(choice, litellm.utils.StreamingChoices):- choice.delta.content = "redacted-by-litellm"+ _redact_choice_content(choice)elif isinstance(_result, litellm.ResponsesAPIResponse):if hasattr(_result, "output"):- for output_item in _result.output:- if hasattr(output_item, "content") and isinstance(output_item.content, list):- for content_part in output_item.content:- if hasattr(content_part, "text"):- content_part.text = "redacted-by-litellm"+ _redact_responses_api_output(_result.output)+ # Redact reasoning field in ResponsesAPIResponse+ if hasattr(_result, "reasoning") and _result.reasoning is not None:+ _result.reasoning = Noneelif isinstance(_result, litellm.EmbeddingResponse):if hasattr(_result, "data") and _result.data is not None:_result.data = []diff --git a/tests/logging_callback_tests/test_logging_redaction_e2e_test.py b/tests/logging_callback_tests/test_logging_redaction_e2e_test.pyindex 6b13c877ce9..07ec6126467 100644--- a/tests/logging_callback_tests/test_logging_redaction_e2e_test.py+++ b/tests/logging_callback_tests/test_logging_redaction_e2e_test.py@@ -202,6 +202,89 @@ async def test_redaction_responses_api_stream():)+async def test_redaction_responses_api_with_reasoning_summary():+ """Test that reasoning summary in ResponsesAPIResponse output is properly redacted"""+ from litellm.litellm_core_utils.redact_messages import perform_redaction++ # Create a simple mock object with output items that have reasoning summaries+ class MockResponsesAPIResponse:+ def __init__(self):+ self.output = [+ # Reasoning item with summary+ type('obj', (object,), {+ 'type': 'reasoning',+ 'id': 'rs_123',+ 'summary': [+ type('obj', (object,), {+ 'text': 'This is a detailed reasoning summary that should be redacted',+ 'type': 'summary_text'+ })()+ ]+ })(),+ # Message item with content+ type('obj', (object,), {+ 'type': 'message',+ 'id': 'msg_123',+ 'content': [+ type('obj', (object,), {+ 'text': 'This is the actual message content',+ 'type': 'output_text'+ })()+ ]+ })()+ ]+ self.reasoning = {"effort": "low", "summary": "auto"}++ # Mock as ResponsesAPIResponse so perform_redaction recognizes it+ mock_response = MockResponsesAPIResponse()+ mock_response.__class__.__name__ = 'ResponsesAPIResponse'++ # Patch isinstance to recognize our mock as ResponsesAPIResponse+ import litellm+ original_isinstance = isinstance+ def patched_isinstance(obj, cls):+ if cls == litellm.ResponsesAPIResponse and obj.__class__.__name__ == 'ResponsesAPIResponse':+ return True+ return original_isinstance(obj, cls)++ import builtins+ builtins.isinstance = patched_isinstance++ try:+ model_call_details = {+ "messages": [{"role": "user", "content": "test"}],+ "prompt": "test prompt",+ "input": "test input"+ }++ # Perform redaction+ redacted_result = perform_redaction(model_call_details, mock_response)++ # Verify reasoning summary text is redacted+ reasoning_item = redacted_result.output[0]+ assert reasoning_item.summary[0].text == "redacted-by-litellm", \+ "Reasoning summary text should be redacted"++ # Verify message content is also redacted+ message_item = redacted_result.output[1]+ assert message_item.content[0].text == "redacted-by-litellm", \+ "Message content text should be redacted"++ # Verify top-level reasoning field is removed+ assert redacted_result.reasoning is None, \+ "Top-level reasoning field should be None"++ # Verify input messages are redacted+ assert model_call_details["messages"][0]["content"] == "redacted-by-litellm", \+ "Input messages should be redacted"++ print("✓ Reasoning summary redaction test passed")+ finally:+ # Restore original isinstance+ builtins.isinstance = original_isinstance++@pytest.mark.asyncioasync def test_redaction_with_coroutine_objects():"""Test that redaction handles coroutine objects correctly without pickle errors"""