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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Bug fix] s3 v2 log uploader crashes when using with guardrails (#12733)
Ishaan Jaffd227085e0365
diff --git a/litellm/integrations/s3_v2.py b/litellm/integrations/s3_v2.pyindex 09a58498e15..7df3e58b2da 100644--- a/litellm/integrations/s3_v2.py+++ b/litellm/integrations/s3_v2.py@@ -7,7 +7,6 @@ NOTE 1: S3 does not provide a BATCH PUT API endpoint, so we create tasks to uplo"""import asyncio-import jsonfrom datetime import datetimefrom typing import List, Optional, cast@@ -15,6 +14,7 @@ import litellmfrom litellm._logging import print_verbose, verbose_loggerfrom litellm.constants import DEFAULT_S3_BATCH_SIZE, DEFAULT_S3_FLUSH_INTERVAL_SECONDSfrom litellm.integrations.s3 import get_s3_object_key+from litellm.litellm_core_utils.safe_json_dumps import safe_dumpsfrom litellm.llms.bedrock.base_aws_llm import BaseAWSLLMfrom litellm.llms.custom_httpx.http_handler import (_get_httpx_client,@@ -281,7 +281,7 @@ class S3Logger(CustomBatchLogger, BaseAWSLLM):url = self.s3_endpoint_url + "/" + batch_logging_element.s3_object_key# Convert JSON to string- json_string = json.dumps(batch_logging_element.payload)+ json_string = safe_dumps(batch_logging_element.payload)# Calculate SHA256 hash of the contentcontent_hash = hashlib.sha256(json_string.encode("utf-8")).hexdigest()@@ -421,7 +421,7 @@ class S3Logger(CustomBatchLogger, BaseAWSLLM):url = self.s3_endpoint_url + "/" + batch_logging_element.s3_object_key# Convert JSON to string- json_string = json.dumps(batch_logging_element.payload)+ json_string = safe_dumps(batch_logging_element.payload)# Calculate SHA256 hash of the contentcontent_hash = hashlib.sha256(json_string.encode("utf-8")).hexdigest()diff --git a/tests/test_litellm/integrations/test_s3_v2.py b/tests/test_litellm/integrations/test_s3_v2.pynew file mode 100644index 00000000000..ea14a4c8017--- /dev/null+++ b/tests/test_litellm/integrations/test_s3_v2.py@@ -0,0 +1,24 @@+import asyncio+from datetime import datetime+from unittest.mock import MagicMock, patch++import pytest++from litellm.integrations.s3_v2 import S3Logger+from litellm.types.utils import StandardLoggingPayload+++class TestS3V2UnitTests:+ """Test that S3 v2 integration only uses safe_dumps and not json.dumps"""+ def test_s3_v2_source_code_analysis(self):+ """Test that S3 v2 source code only imports and uses safe_dumps"""+ import inspect++ from litellm.integrations import s3_v2++ # Get the source code of the s3_v2 module+ source_code = inspect.getsource(s3_v2)++ # Verify that json.dumps is not used directly in the code+ assert "json.dumps(" not in source_code, \+ "S3 v2 should not use json.dumps directly"\ No newline at end of file