Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: correct formatting of alert messages in Slack notifications

Marcelo Mendoza92f631d57c88
diff --git a/litellm/integrations/SlackAlerting/slack_alerting.py b/litellm/integrations/SlackAlerting/slack_alerting.py
index 0953fb768cb..6d705642667 100644
--- a/litellm/integrations/SlackAlerting/slack_alerting.py
+++ b/litellm/integrations/SlackAlerting/slack_alerting.py
@@ -1371,7 +1371,7 @@ Model Info:
if alert_type == "daily_reports" or alert_type == "new_model_added":
formatted_message = alert_type_formatted + message
else:
- formatted_message = f"{alert_type_formatted}\n Level: `{level}`\nTimestamp: `{current_time}`\n\nMessage: {message}"
+ formatted_message = f"{alert_type_formatted}\nLevel: `{level}`\nTimestamp: `{current_time}`\n\nMessage: {message}"
if kwargs:
for key, value in kwargs.items():
diff --git a/tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py b/tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py
index d389be79618..7e1bd897908 100644
--- a/tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py
+++ b/tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py
@@ -172,3 +172,27 @@ class TestSlackAlerting(unittest.TestCase):
self.slack_alerting.update_values(alerting_args={"slack_alerting": "True"})
assert self.slack_alerting.periodic_started == True
+
+ @patch("litellm.integrations.SlackAlerting.slack_alerting.datetime")
+ def test_alert_type_in_formatted_message(self, mock_datetime):
+ # Setup mocks
+ mock_datetime.now.return_value.strftime.return_value = "12:34:56"
+
+ # Import required types
+ from litellm.types.integrations.slack_alerting import AlertType
+
+ # Create a simple test message to check formatting
+ alert_type = AlertType.llm_exceptions
+ level = "Medium"
+ message = "Test alert message"
+ current_time = "12:34:56"
+
+ # Test the specific formatting logic we're interested in
+ alert_type_formatted = f"Alert type: `{alert_type}`\n"
+ formatted_message = f"{alert_type_formatted}\n Level: `{level}`\nTimestamp: `{current_time}`\n\nMessage: {message}"
+
+ # Verify alert_type is in the formatted message as expected
+ self.assertIn("Alert type: `AlertType.llm_exceptions`", formatted_message)
+ self.assertIn("Level: `Medium`", formatted_message)
+ self.assertIn("Timestamp: `12:34:56`", formatted_message)
+ self.assertIn("Message: Test alert message", formatted_message)