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 empty stop string

Krrish Dholakia526b196f837c
diff --git a/litellm/llms/bedrock_httpx.py b/litellm/llms/bedrock_httpx.py
index 64d57744202..3434371f6ee 100644
--- a/litellm/llms/bedrock_httpx.py
+++ b/litellm/llms/bedrock_httpx.py
@@ -1394,6 +1394,8 @@ class AmazonConverseConfig:
optional_params["stream"] = value
if param == "stop":
if isinstance(value, str):
+ if len(value) == 0: # converse raises error for empty strings
+ continue
value = [value]
optional_params["stop_sequences"] = value
if param == "temperature":
diff --git a/litellm/tests/test_bedrock_completion.py b/litellm/tests/test_bedrock_completion.py
index 3937cada8bd..5f49bbd2c6c 100644
--- a/litellm/tests/test_bedrock_completion.py
+++ b/litellm/tests/test_bedrock_completion.py
@@ -636,6 +636,45 @@ def test_bedrock_claude_3(image_url):
pytest.fail(f"Error occurred: {e}")
+ "stop",
+ [""],
+)
+ "model",
+ [
+ "anthropic.claude-3-sonnet-20240229-v1:0",
+ # "meta.llama3-70b-instruct-v1:0",
+ # "anthropic.claude-v2",
+ # "mistral.mixtral-8x7b-instruct-v0:1",
+ ],
+)
+def test_bedrock_stop_value(stop, model):
+ try:
+ litellm.set_verbose = True
+ data = {
+ "max_tokens": 100,
+ "stream": False,
+ "temperature": 0.3,
+ "messages": [
+ {"role": "user", "content": "hey, how's it going?"},
+ ],
+ "stop": stop,
+ }
+ response: ModelResponse = completion(
+ model="bedrock/{}".format(model),
+ **data,
+ ) # type: ignore
+ # Add any assertions here to check the response
+ assert len(response.choices) > 0
+ assert len(response.choices[0].message.content) > 0
+
+ except RateLimitError:
+ pass
+ except Exception as e:
+ pytest.fail(f"Error occurred: {e}")
+
+
@pytest.mark.parametrize(
"system",
["You are an AI", [{"type": "text", "text": "You are an AI"}], ""],