From cb177053b70496635b1b7ad4fe07fe75f1194fdd Mon Sep 17 00:00:00 2001 From: alihacks Date: Fri, 24 Apr 2026 16:35:25 -0400 Subject: [PATCH] azure_sentinel_truncate fix P1 issues --- litellm/integrations/azure_sentinel/azure_sentinel.py | 6 ++++-- tests/test_litellm/integrations/test_azure_sentinel.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/integrations/azure_sentinel/azure_sentinel.py b/litellm/integrations/azure_sentinel/azure_sentinel.py index f70c40280a9..a74b943574b 100644 --- a/litellm/integrations/azure_sentinel/azure_sentinel.py +++ b/litellm/integrations/azure_sentinel/azure_sentinel.py @@ -284,13 +284,15 @@ class AzureSentinelLogger(CustomBatchLogger): entry = deepcopy(payload) truncated_fields: List[str] = [] + prefix = "[truncated by litellm]..." + tail_limit = limit - len(prefix) if len(msg_str) > limit: - entry["messages"] = "[truncated by litellm]..." + msg_str[-limit:] + entry["messages"] = prefix + msg_str[-tail_limit:] truncated_fields.append("messages") if len(resp_str) > limit: - entry["response"] = "[truncated by litellm]..." + resp_str[-limit:] + entry["response"] = prefix + resp_str[-tail_limit:] truncated_fields.append("response") truncation_info: Dict[str, Any] = { diff --git a/tests/test_litellm/integrations/test_azure_sentinel.py b/tests/test_litellm/integrations/test_azure_sentinel.py index de710c72fac..7bc0ff2f7c2 100644 --- a/tests/test_litellm/integrations/test_azure_sentinel.py +++ b/tests/test_litellm/integrations/test_azure_sentinel.py @@ -199,11 +199,12 @@ def test_column_limit_truncates_large_fields(): # Messages field should be truncated, keeping tail msg_str = str(result["messages"]) assert msg_str.startswith("[truncated by litellm]...") - assert len(msg_str) <= logger.MAX_COLUMN_CHARS + len("[truncated by litellm]...") + assert len(msg_str) <= logger.MAX_COLUMN_CHARS # Response field should be truncated, keeping tail resp_str = str(result["response"]) assert resp_str.startswith("[truncated by litellm]...") + assert len(resp_str) <= logger.MAX_COLUMN_CHARS # Truncation metadata present metadata = result.get("metadata", {})