From 8bb7e19a652c3d4e4bf6154cac67ed4bd15e882b Mon Sep 17 00:00:00 2001 From: yucheng Date: Mon, 14 Sep 2026 22:37:45 +0000 Subject: [PATCH] fix(logging): tolerate null callback_settings entries Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/litellm_core_utils/litellm_logging.py | 5 ++--- .../test_litellm_logging.py | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 076c5fae28f..e26c50a0888 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -5278,9 +5278,8 @@ def _get_custom_logger_settings_from_proxy_server(callback_name: str) -> dict: langsmith: turn_off_message_logging: true """ - if litellm.callback_settings: - return dict(litellm.callback_settings.get(callback_name, {})) - return {} + callback_settings: Final = litellm.callback_settings.get(callback_name) if litellm.callback_settings else None + return dict(callback_settings) if isinstance(callback_settings, dict) else {} def use_custom_pricing_for_model(litellm_params: dict | None) -> bool: diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py index bc840ff517b..de882a48c2f 100644 --- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py +++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py @@ -1046,6 +1046,26 @@ def test_init_custom_logger_applies_callback_settings_turn_off_message_logging(m logging_module._in_memory_loggers.clear() +def test_init_custom_logger_tolerates_null_callback_settings(monkeypatch): + from litellm.litellm_core_utils import litellm_logging as logging_module + + monkeypatch.setattr(litellm, "callback_settings", {"langsmith": None}) + logging_module._in_memory_loggers.clear() + try: + logger = logging_module._init_custom_logger_compatible_class( + logging_integration="langsmith", + internal_usage_cache=None, + llm_router=None, + custom_logger_init_args={}, + ) + + assert logger is not None + assert logger.turn_off_message_logging is False + assert logging_module._get_custom_logger_settings_from_proxy_server("langsmith") == {} + finally: + logging_module._in_memory_loggers.clear() + + def test_success_handler_redacts_custom_logger_payload_per_callback(logging_obj): redacting_logger = _RecordingCustomLogger(turn_off_message_logging=True) plain_logger = _RecordingCustomLogger(turn_off_message_logging=False)