fix(proxy): redact the logged messages of a request refused for its model

This commit is contained in:
yucheng 2026-10-30 17:35:29 -07:00
parent 10795ef3b4
commit cd4769a363
2 changed files with 29 additions and 2 deletions

View file

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

View file

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