From 98cbd9af71ef0a23c4d643609d6294297d65f773 Mon Sep 17 00:00:00 2001 From: moe-berri Date: Thu, 29 Oct 2026 18:32:31 -0700 Subject: [PATCH] fix(logging): preserve retry diagnostics without exceptions --- litellm/integrations/deepeval/api.py | 8 ++++++-- tests/unit/integrations/test_deepeval.py | 13 ++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/litellm/integrations/deepeval/api.py b/litellm/integrations/deepeval/api.py index b519f4e45bb..cc1c12b16bb 100644 --- a/litellm/integrations/deepeval/api.py +++ b/litellm/integrations/deepeval/api.py @@ -22,10 +22,14 @@ from litellm.llms.custom_httpx.http_handler import ( def log_retry_error(details): - exception: Final = "redacted-by-litellm" if litellm.redact_messages_in_debug_logs else details.get("exception") + exception: Final = details.get("exception") tries: Final = "redacted-by-litellm" if litellm.redact_messages_in_debug_logs else details.get("tries") if exception: - logging.error("Confident AI Error: %s. Retrying: %s time(s)...", exception, tries) + logging.error( + "Confident AI Error: %s. Retrying: %s time(s)...", + "redacted-by-litellm" if litellm.redact_messages_in_debug_logs else exception, + tries, + ) else: logging.error("Retrying: %s time(s)...", tries) diff --git a/tests/unit/integrations/test_deepeval.py b/tests/unit/integrations/test_deepeval.py index eef9a0a340d..09cb2873ff1 100644 --- a/tests/unit/integrations/test_deepeval.py +++ b/tests/unit/integrations/test_deepeval.py @@ -126,16 +126,19 @@ if __name__ == "__main__": @pytest.mark.parametrize("redact", (False, True)) +@pytest.mark.parametrize("exception_kind", ("missing", "none", "error")) def test_retry_diagnostic_hides_exception_and_dynamic_details_only_when_opted_in( - redact: bool, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch + redact: bool, exception_kind: str, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch ) -> None: from litellm.integrations.deepeval.api import log_retry_error monkeypatch.setattr(litellm, "redact_messages_in_debug_logs", redact) marker: Final = "synthetic-private-retry-content" - failure: Final = ValueError(marker) - details: Final = {"exception": failure, "tries": 2} + failure: Final = ValueError(marker) if exception_kind == "error" else None + details: Final = {"tries": 2} if exception_kind == "missing" else {"exception": failure, "tries": 2} log_retry_error(details) - assert (marker in caplog.text) is not redact + assert ("Confident AI Error:" in caplog.text) is (failure is not None) + assert (marker in caplog.text) is (failure is not None and not redact) assert ("redacted-by-litellm" in caplog.text) is redact - assert details["exception"] is failure + assert details.get("exception") is failure + assert ("exception" in details) is (exception_kind != "missing")