diff --git a/litellm/integrations/custom_logger.py b/litellm/integrations/custom_logger.py index c244363e389..59e3b7a5007 100644 --- a/litellm/integrations/custom_logger.py +++ b/litellm/integrations/custom_logger.py @@ -771,7 +771,9 @@ class CustomLogger: # https://docs.litellm.ai/docs/observability/custom_callbac return OLD_LITELLM_METADATA_FIELD def redact_standard_logging_payload_from_model_call_details( - self, model_call_details: Dict + self, + model_call_details: Dict, + global_redaction_applied: bool = False, ) -> Dict: """ Redacts or excludes fields from StandardLoggingPayload before callbacks receive it. @@ -784,6 +786,10 @@ class CustomLogger: # https://docs.litellm.ai/docs/observability/custom_callbac This is useful for logging payloads that contain sensitive information. """ + # skip redundant redaction if global redaction was already applied + if global_redaction_applied: + return model_call_details + import litellm from copy import copy diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index bdbbc7579b7..31db3fb42eb 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -68,6 +68,7 @@ from litellm.litellm_core_utils.model_param_helper import ModelParamHelper from litellm.litellm_core_utils.redact_messages import ( redact_message_input_output_from_custom_logger, redact_message_input_output_from_logging, + should_redact_message_logging, ) from litellm.llms.base_llm.ocr.transformation import OCRResponse from litellm.llms.base_llm.search.transformation import SearchResponse @@ -2483,10 +2484,10 @@ class Logging(LiteLLMLoggingBaseClass): global_callbacks=litellm._async_success_callback, ) + _model_call_details = self.model_call_details if hasattr(self, "model_call_details") else {} + global_redaction_applied = should_redact_message_logging(_model_call_details) result = redact_message_input_output_from_logging( - model_call_details=( - self.model_call_details if hasattr(self, "model_call_details") else {} - ), + model_call_details=_model_call_details, result=result, ) @@ -2512,7 +2513,10 @@ class Logging(LiteLLMLoggingBaseClass): ) elif isinstance(callback, CustomLogger): result = redact_message_input_output_from_custom_logger( - result=result, litellm_logging_obj=self, custom_logger=callback + result=result, + litellm_logging_obj=self, + custom_logger=callback, + global_redaction_applied=global_redaction_applied, ) self.model_call_details, result = await callback.async_logging_hook( kwargs=self.model_call_details, @@ -2567,7 +2571,8 @@ class Logging(LiteLLMLoggingBaseClass): ################################## # call redaction hook for custom logger model_call_details = callback.redact_standard_logging_payload_from_model_call_details( - model_call_details=model_call_details + model_call_details=model_call_details, + global_redaction_applied=global_redaction_applied, ) ################################## if self.stream is True: diff --git a/litellm/litellm_core_utils/redact_messages.py b/litellm/litellm_core_utils/redact_messages.py index 5d6d1fbc1c5..e9d9bcf8096 100644 --- a/litellm/litellm_core_utils/redact_messages.py +++ b/litellm/litellm_core_utils/redact_messages.py @@ -30,8 +30,15 @@ else: def redact_message_input_output_from_custom_logger( - litellm_logging_obj: LiteLLMLoggingObject, result, custom_logger: CustomLogger + litellm_logging_obj: LiteLLMLoggingObject, + result, + custom_logger: CustomLogger, + global_redaction_applied: bool = False, ): + # skip redundant redaction if global redaction was already applied + if global_redaction_applied: + return result + if ( hasattr(custom_logger, "message_logging") and custom_logger.message_logging is not True