fix(logging): keep AttributeError for non-mapping redaction headers
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled

The lint-gate retype read a non-mapping headers carrier as empty headers, so
should_redact_message_logging returned the global flag where main raised
AttributeError. The complexity router reads that error as an undecidable
request and withholds the classifier reply, so a request with headers=None
logged the raw reply again (test_llm_v2 undecidable-headers-fail-closed).
This commit is contained in:
yucheng-berri 2026-10-10 04:15:09 -07:00
parent 20f25a9459
commit 52549ea351

View file

@ -500,7 +500,11 @@ def should_redact_message_logging(model_call_details: Mapping) -> bool:
) )
# Get headers from the metadata # Get headers from the metadata
request_headers: Final = _str_keyed_mapping(metadata.get("headers")) raw_headers: Final = metadata.get("headers", {})
if not isinstance(raw_headers, Mapping):
# Callers such as the complexity router read AttributeError as an undecidable request and redact
raise AttributeError(f"request headers are {type(raw_headers).__name__}, not a mapping") # noqa: TRY004 # callers catch AttributeError
request_headers: Final = _str_keyed_mapping(raw_headers)
# Check for headers that explicitly control redaction # Check for headers that explicitly control redaction
if request_headers and bool(request_headers.get("litellm-disable-message-redaction", False)): if request_headers and bool(request_headers.get("litellm-disable-message-redaction", False)):