From 5e147c685df29133538f8d09dd30ff394995adc0 Mon Sep 17 00:00:00 2001 From: Ryan Crabbe Date: Thu, 12 Mar 2026 09:42:59 -0700 Subject: [PATCH] fix: use redacted exc_text in JsonFormatter, snapshot dict iteration in filter JsonFormatter.format() was calling self.formatException(record.exc_info) directly, bypassing the already-redacted record.exc_text set by SecretRedactionFilter. Now uses record.exc_text when available. Also snapshot record.__dict__.items() with list() as defensive measure against potential dict mutation during iteration. --- litellm/_logging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/_logging.py b/litellm/_logging.py index 14cb10c9c8c..d964092e10c 100644 --- a/litellm/_logging.py +++ b/litellm/_logging.py @@ -87,7 +87,7 @@ class SecretRedactionFilter(logging.Filter): pass # Redact extra fields passed via logger.debug("msg", extra={...}) - for key, value in record.__dict__.items(): + for key, value in list(record.__dict__.items()): if key not in _STANDARD_RECORD_ATTRS and isinstance(value, str): setattr(record, key, _redact_string(value)) @@ -199,7 +199,7 @@ class JsonFormatter(Formatter): json_record[key] = value if record.exc_info: - json_record["stacktrace"] = self.formatException(record.exc_info) + json_record["stacktrace"] = record.exc_text or self.formatException(record.exc_info) return safe_dumps(json_record)