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(bedrock_httpx.py): handle bedrock empty system message

Krrish Dholakia6e8d2856b0c8
diff --git a/litellm/llms/bedrock_httpx.py b/litellm/llms/bedrock_httpx.py
index a92288b6ffa..64d57744202 100644
--- a/litellm/llms/bedrock_httpx.py
+++ b/litellm/llms/bedrock_httpx.py
@@ -1912,13 +1912,15 @@ class BedrockConverseLLM(BaseLLM):
system_content_blocks: List[SystemContentBlock] = []
for idx, message in enumerate(messages):
if message["role"] == "system":
- if isinstance(message["content"], str):
+ _system_content_block: Optional[SystemContentBlock] = None
+ if isinstance(message["content"], str) and len(message["content"]) > 0:
_system_content_block = SystemContentBlock(text=message["content"])
elif isinstance(message["content"], list):
for m in message["content"]:
- if m.get("type", "") == "text":
+ if m.get("type", "") == "text" and len(m["text"]) > 0:
_system_content_block = SystemContentBlock(text=m["text"])
- system_content_blocks.append(_system_content_block)
+ if _system_content_block is not None:
+ system_content_blocks.append(_system_content_block)
system_prompt_indices.append(idx)
if len(system_prompt_indices) > 0:
for idx in reversed(system_prompt_indices):
diff --git a/litellm/tests/test_bedrock_completion.py b/litellm/tests/test_bedrock_completion.py
index f97fbf0303d..3937cada8bd 100644
--- a/litellm/tests/test_bedrock_completion.py
+++ b/litellm/tests/test_bedrock_completion.py
@@ -638,7 +638,7 @@ def test_bedrock_claude_3(image_url):
@pytest.mark.parametrize(
"system",
- ["You are an AI", [{"type": "text", "text": "You are an AI"}]],
+ ["You are an AI", [{"type": "text", "text": "You are an AI"}], ""],
)
@pytest.mark.parametrize(
"model",