From 8ff4e111bb2645b9645e141312c45b4e6ce8bed4 Mon Sep 17 00:00:00 2001 From: Dean Schmigelski Date: Fri, 14 Nov 2025 12:47:50 -0500 Subject: [PATCH 1/2] feat(models): add validation for stream parameter in LiteLLM - Raise ValueError when stream is explicitly set to False - Add unit test for stream parameter validation --- src/strands/models/litellm.py | 2 ++ tests/strands/models/test_litellm.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/strands/models/litellm.py b/src/strands/models/litellm.py index f2480c8d8..17f1bbb94 100644 --- a/src/strands/models/litellm.py +++ b/src/strands/models/litellm.py @@ -272,6 +272,8 @@ async def stream( logger.debug("invoking model") try: + if kwargs.get("stream") is False: + raise ValueError("stream parameter cannot be explicitly set to False") response = await litellm.acompletion(**self.client_args, **request) except ContextWindowExceededError as e: logger.warning("litellm client raised context window overflow") diff --git a/tests/strands/models/test_litellm.py b/tests/strands/models/test_litellm.py index f56438cf5..982bee268 100644 --- a/tests/strands/models/test_litellm.py +++ b/tests/strands/models/test_litellm.py @@ -408,6 +408,16 @@ async def test_context_window_maps_to_typed_exception(litellm_acompletion, model pass +@pytest.mark.asyncio +async def test_stream_raises_error_when_stream_is_false(model): + """Test that stream raises ValueError when stream parameter is explicitly False.""" + messages = [{"role": "user", "content": [{"text": "test"}]}] + + with pytest.raises(ValueError, match="stream parameter cannot be explicitly set to False"): + async for _ in model.stream(messages, stream=False): + pass + + def test_format_request_messages_with_system_prompt_content(): """Test format_request_messages with system_prompt_content parameter.""" messages = [{"role": "user", "content": [{"text": "Hello"}]}] From d69fa231d5075ceb29c4a3b961742cc8a8e487be Mon Sep 17 00:00:00 2001 From: Dean Schmigelski Date: Fri, 14 Nov 2025 12:53:03 -0500 Subject: [PATCH 2/2] formatting --- tests/strands/models/test_litellm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/strands/models/test_litellm.py b/tests/strands/models/test_litellm.py index 982bee268..aafee1d17 100644 --- a/tests/strands/models/test_litellm.py +++ b/tests/strands/models/test_litellm.py @@ -412,7 +412,7 @@ async def test_context_window_maps_to_typed_exception(litellm_acompletion, model async def test_stream_raises_error_when_stream_is_false(model): """Test that stream raises ValueError when stream parameter is explicitly False.""" messages = [{"role": "user", "content": [{"text": "test"}]}] - + with pytest.raises(ValueError, match="stream parameter cannot be explicitly set to False"): async for _ in model.stream(messages, stream=False): pass