diff --git a/litellm/litellm_core_utils/initialize_dynamic_callback_params.py b/litellm/litellm_core_utils/initialize_dynamic_callback_params.py index 78846f8e82c..ff521d47804 100644 --- a/litellm/litellm_core_utils/initialize_dynamic_callback_params.py +++ b/litellm/litellm_core_utils/initialize_dynamic_callback_params.py @@ -27,6 +27,7 @@ _supported_callback_params = [ "braintrust_host", "slack_webhook_url", "lunary_public_key", + "turn_off_message_logging", ] diff --git a/litellm/litellm_core_utils/redact_messages.py b/litellm/litellm_core_utils/redact_messages.py index 0effed3db70..aa763dc9899 100644 --- a/litellm/litellm_core_utils/redact_messages.py +++ b/litellm/litellm_core_utils/redact_messages.py @@ -130,6 +130,11 @@ def perform_redaction(model_call_details: dict, result): def should_redact_message_logging(model_call_details: dict) -> bool: """ Determine if message logging should be redacted. + + Priority order: + 1. Dynamic parameter (turn_off_message_logging in request) + 2. Headers (litellm-disable-message-redaction / litellm-enable-message-redaction) + 3. Global setting (litellm.turn_off_message_logging) """ litellm_params = model_call_details.get("litellm_params", {}) @@ -139,36 +144,36 @@ def should_redact_message_logging(model_call_details: dict) -> bool: # Get headers from the metadata request_headers = metadata.get("headers", {}) if isinstance(metadata, dict) else {} - possible_request_headers = [ + # Check for headers that explicitly control redaction + if request_headers and bool( + request_headers.get("litellm-disable-message-redaction", False) + ): + # User explicitly disabled redaction via header + return False + + possible_enable_headers = [ "litellm-enable-message-redaction", # old header. maintain backwards compatibility "x-litellm-enable-message-redaction", # new header ] is_redaction_enabled_via_header = False - for header in possible_request_headers: + for header in possible_enable_headers: if bool(request_headers.get(header, False)): is_redaction_enabled_via_header = True break - # check if user opted out of logging message/response to callbacks - if ( - litellm.turn_off_message_logging is not True - and is_redaction_enabled_via_header is not True - and _get_turn_off_message_logging_from_dynamic_params(model_call_details) - is not True - ): - return False - - if request_headers and bool( - request_headers.get("litellm-disable-message-redaction", False) - ): - return False - - # user has OPTED OUT of message redaction - if _get_turn_off_message_logging_from_dynamic_params(model_call_details) is False: - return False - - return True + # Priority 1: Check dynamic parameter first (if explicitly set) + dynamic_turn_off = _get_turn_off_message_logging_from_dynamic_params(model_call_details) + if dynamic_turn_off is not None: + # Dynamic parameter is explicitly set, use it + return dynamic_turn_off + + # Priority 2: Check if header explicitly enables redaction + if is_redaction_enabled_via_header: + return True + + # Priority 3: Fall back to global setting + return litellm.turn_off_message_logging is True def redact_message_input_output_from_logging(