Skip to content

Commit ded0934

Browse files
fix(litellm): add validation for stream parameter in LiteLLM (#1183)
1 parent cee5145 commit ded0934

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/strands/models/litellm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ async def stream(
272272

273273
logger.debug("invoking model")
274274
try:
275+
if kwargs.get("stream") is False:
276+
raise ValueError("stream parameter cannot be explicitly set to False")
275277
response = await litellm.acompletion(**self.client_args, **request)
276278
except ContextWindowExceededError as e:
277279
logger.warning("litellm client raised context window overflow")

tests/strands/models/test_litellm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,16 @@ async def test_context_window_maps_to_typed_exception(litellm_acompletion, model
408408
pass
409409

410410

411+
@pytest.mark.asyncio
412+
async def test_stream_raises_error_when_stream_is_false(model):
413+
"""Test that stream raises ValueError when stream parameter is explicitly False."""
414+
messages = [{"role": "user", "content": [{"text": "test"}]}]
415+
416+
with pytest.raises(ValueError, match="stream parameter cannot be explicitly set to False"):
417+
async for _ in model.stream(messages, stream=False):
418+
pass
419+
420+
411421
def test_format_request_messages_with_system_prompt_content():
412422
"""Test format_request_messages with system_prompt_content parameter."""
413423
messages = [{"role": "user", "content": [{"text": "Hello"}]}]

0 commit comments

Comments
 (0)