diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py index 69284fa64e8..4e9605cc4a3 100644 --- a/litellm/proxy/common_request_processing.py +++ b/litellm/proxy/common_request_processing.py @@ -46,6 +46,7 @@ from litellm.constants import ( MAX_LITELLM_CALL_ID_LENGTH, MAX_PAYLOAD_SIZE_FOR_DEBUG_LOG, NON_INFERENCE_CALL_TYPES, + REDACTED_BY_LITELLM, RETURN_RAW_MODEL_NAME_METADATA_KEY, STREAM_SSE_DATA_PREFIX, STREAM_SSE_KEEPALIVE_PING_BYTES, @@ -2704,11 +2705,14 @@ class ProxyBaseLLMRequestProcessing: return self.data, logging_obj def _redact_request_its_skipped_guardrails_never_scanned(self) -> None: - """Redact the request body and its logged snapshot, so failure callbacks never see content a skipped - masking guardrail would have rewritten. + """Redact the request body, its logged snapshot and the logged messages, so failure callbacks never see + content a skipped masking guardrail would have rewritten. """ self.data.update(without_unscanned_content(self.data)) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] # self.data is the untyped request dict refresh_proxy_server_request_body_snapshot(self.data) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] # self.data is the untyped request dict + logging_obj: Final = self.data.get("litellm_logging_obj") # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] # self.data is the untyped request dict + if isinstance(logging_obj, LiteLLMLoggingObj): + logging_obj.update_messages([{"role": "user", "content": REDACTED_BY_LITELLM}]) async def _pre_call_with_fallbacks( self, diff --git a/tests/unit/proxy/test_common_request_processing.py b/tests/unit/proxy/test_common_request_processing.py index fbcb751277f..6b94319ae06 100644 --- a/tests/unit/proxy/test_common_request_processing.py +++ b/tests/unit/proxy/test_common_request_processing.py @@ -13425,6 +13425,29 @@ class TestUnroutableModelFailureLogHidesUnscannedContent: assert sent.status == 400 assert _shows_no_raw_content(sent), sent.failure_dumps + @pytest.mark.asyncio + @pytest.mark.parametrize( + ("route_type", "body"), + [ + pytest.param( + "aresponses", {"input": [{"role": "user", "content": f"email {_RAW_EMAIL}"}]}, id="responses-list" + ), + pytest.param( + "aresponses", + {"input": [{"role": "user", "content": [{"type": "input_text", "text": f"email {_RAW_EMAIL}"}]}]}, + id="responses-input-text-parts", + ), + pytest.param("aresponses", {}, id="responses-string"), + pytest.param("aembedding", {"input": [f"email {_RAW_EMAIL}"]}, id="embeddings-list"), + pytest.param("atext_completion", {}, id="completions"), + ], + ) + async def test_failure_log_hides_the_input_of_other_routes(self, monkeypatch, route_type, body): + sent: Final = await _send(monkeypatch, [_VendorGuardrail(behavior="mask")], route_type=route_type, body=body) + + assert sent.status == 400 + assert _shows_no_raw_content(sent), sent.failure_dumps + @pytest.mark.asyncio async def test_failure_log_hides_content_a_skipped_parallel_guardrail_would_have_scanned( self, monkeypatch: pytest.MonkeyPatch