Litellm staging (#8270)
All checks were successful
Read Version from pyproject.toml / read-version (push) Successful in 15s

* fix(opik.py): cleanup

* docs(opik_integration.md): cleanup opik integration docs

* fix(redact_messages.py): fix redact messages check header logic

ensures stringified bool value in header is still asserted to true

 allows dynamic message redaction

* feat(redact_messages.py): support `x-litellm-enable-message-redaction` request header

allows dynamic message redaction
This commit is contained in:
Krish Dholakia 2025-02-04 22:35:48 -08:00 committed by GitHub
parent 3c813b3a87
commit 8d3a942fbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 258 additions and 66 deletions

View file

@ -73,12 +73,9 @@ def perform_redaction(model_call_details: dict, result):
return {"text": "redacted-by-litellm"}
def redact_message_input_output_from_logging(
model_call_details: dict, result, input: Optional[Any] = None
):
def should_redact_message_logging(model_call_details: dict) -> bool:
"""
Removes messages, prompts, input, response from logging. This modifies the data in-place
only redacts when litellm.turn_off_message_logging == True
Determine if message logging should be redacted.
"""
_request_headers = (
model_call_details.get("litellm_params", {}).get("metadata", {}) or {}
@ -86,25 +83,48 @@ def redact_message_input_output_from_logging(
request_headers = _request_headers.get("headers", {})
possible_request_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:
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 request_headers.get("litellm-enable-message-redaction", False) 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 result
return False
if request_headers and request_headers.get(
"litellm-disable-message-redaction", False
if request_headers and bool(
request_headers.get("litellm-disable-message-redaction", False)
):
return result
return False
# user has OPTED OUT of message redaction
if _get_turn_off_message_logging_from_dynamic_params(model_call_details) is False:
return result
return False
return perform_redaction(model_call_details, result)
return True
def redact_message_input_output_from_logging(
model_call_details: dict, result, input: Optional[Any] = None
) -> Any:
"""
Removes messages, prompts, input, response from logging. This modifies the data in-place
only redacts when litellm.turn_off_message_logging == True
"""
if should_redact_message_logging(model_call_details):
return perform_redaction(model_call_details, result)
return result
def _get_turn_off_message_logging_from_dynamic_params(