From 1e8429bb20bee4abf41ff2f4a72f40670c652585 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 6 Jun 2024 10:38:15 -0700 Subject: [PATCH 1/3] feat - redact messages from slack alerting --- litellm/__init__.py | 1 + litellm/proxy/proxy_config.yaml | 4 +++- litellm/utils.py | 10 +++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/litellm/__init__.py b/litellm/__init__.py index 9fb614396e..33ae7deaba 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -60,6 +60,7 @@ _async_failure_callback: List[Callable] = ( pre_call_rules: List[Callable] = [] post_call_rules: List[Callable] = [] turn_off_message_logging: Optional[bool] = False +redact_messages_in_exceptions: Optional[bool] = False store_audit_logs = False # Enterprise feature, allow users to see audit logs ## end of callbacks ############# diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index 88fc0e9136..2bef95acfd 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -21,7 +21,9 @@ model_list: general_settings: master_key: sk-1234 + alerting: ["slack"] litellm_settings: callbacks: ["otel"] - store_audit_logs: true \ No newline at end of file + store_audit_logs: true + redact_messages_in_exceptions: True \ No newline at end of file diff --git a/litellm/utils.py b/litellm/utils.py index ba6a374674..91e6d9faba 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -7351,10 +7351,10 @@ def get_provider_fields(custom_llm_provider: str) -> List[ProviderField]: if custom_llm_provider == "databricks": return litellm.DatabricksConfig().get_required_params() - + elif custom_llm_provider == "ollama": return litellm.OllamaConfig().get_required_params() - + else: return [] @@ -8514,7 +8514,11 @@ def exception_type( extra_information = f"\nModel: {model}" if _api_base: extra_information += f"\nAPI Base: `{_api_base}`" - if messages and len(messages) > 0: + if ( + messages + and len(messages) > 0 + and litellm.redact_messages_in_exceptions is False + ): extra_information += f"\nMessages: `{messages}`" if _model_group is not None: From 35684fdf4bc0ab21256e2532d71172841ae31e76 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 6 Jun 2024 10:48:08 -0700 Subject: [PATCH 2/3] fix - turn of message logging --- litellm/integrations/slack_alerting.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.py index c98d60f1fd..ce7039ef15 100644 --- a/litellm/integrations/slack_alerting.py +++ b/litellm/integrations/slack_alerting.py @@ -326,7 +326,7 @@ class SlackAlerting(CustomLogger): end_time=end_time, ) ) - if litellm.turn_off_message_logging: + if litellm.turn_off_message_logging or litellm.redact_messages_in_exceptions: messages = "Message not logged. `litellm.turn_off_message_logging=True`." request_info = f"\nRequest Model: `{model}`\nAPI Base: `{api_base}`\nMessages: `{messages}`" slow_message = f"`Responses are slow - {round(time_difference_float,2)}s response time > Alerting threshold: {self.alerting_threshold}s`" @@ -567,7 +567,10 @@ class SlackAlerting(CustomLogger): except: messages = "" - if litellm.turn_off_message_logging: + if ( + litellm.turn_off_message_logging + or litellm.redact_messages_in_exceptions + ): messages = ( "Message not logged. `litellm.turn_off_message_logging=True`." ) From 64a9fe18270826ad8d2f715303335e362cf4fb23 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 6 Jun 2024 12:30:56 -0700 Subject: [PATCH 3/3] docs - redacting messages from slack alerting --- docs/my-website/docs/proxy/alerting.md | 17 +++++++++++++++++ litellm/integrations/slack_alerting.py | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/my-website/docs/proxy/alerting.md b/docs/my-website/docs/proxy/alerting.md index 3ef676bbd6..402de410c9 100644 --- a/docs/my-website/docs/proxy/alerting.md +++ b/docs/my-website/docs/proxy/alerting.md @@ -62,6 +62,23 @@ curl -X GET 'http://localhost:4000/health/services?service=slack' \ -H 'Authorization: Bearer sk-1234' ``` +## Advanced - Redacting Messages from Alerts + +By default alerts show the `messages/input` passed to the LLM. If you want to redact this from slack alerting set the following setting on your config + + +```shell +general_settings: + alerting: ["slack"] + alert_types: ["spend_reports"] + +litellm_settings: + redact_messages_in_exceptions: True +``` + + + + ## Advanced - Opting into specific alert types Set `alert_types` if you want to Opt into only specific alert types diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.py index ce7039ef15..21415fb6d6 100644 --- a/litellm/integrations/slack_alerting.py +++ b/litellm/integrations/slack_alerting.py @@ -327,7 +327,7 @@ class SlackAlerting(CustomLogger): ) ) if litellm.turn_off_message_logging or litellm.redact_messages_in_exceptions: - messages = "Message not logged. `litellm.turn_off_message_logging=True`." + messages = "Message not logged. litellm.redact_messages_in_exceptions=True" request_info = f"\nRequest Model: `{model}`\nAPI Base: `{api_base}`\nMessages: `{messages}`" slow_message = f"`Responses are slow - {round(time_difference_float,2)}s response time > Alerting threshold: {self.alerting_threshold}s`" if time_difference_float > self.alerting_threshold: @@ -572,7 +572,7 @@ class SlackAlerting(CustomLogger): or litellm.redact_messages_in_exceptions ): messages = ( - "Message not logged. `litellm.turn_off_message_logging=True`." + "Message not logged. litellm.redact_messages_in_exceptions=True" ) request_info = f"\nRequest Model: `{model}`\nMessages: `{messages}`" else: