diff --git a/src/strands/models/litellm.py b/src/strands/models/litellm.py index 486f67bf8..b54d97412 100644 --- a/src/strands/models/litellm.py +++ b/src/strands/models/litellm.py @@ -238,8 +238,8 @@ async def _structured_output_using_response_schema( if len(response.choices) > 1: raise ValueError("Multiple choices found in the response.") - if not response.choices or response.choices[0].finish_reason != "tool_calls": - raise ValueError("No tool_calls found in response") + if not response.choices: + raise ValueError("No choices found in response") choice = response.choices[0] try: diff --git a/tests/strands/models/test_litellm.py b/tests/strands/models/test_litellm.py index 82023cae3..c906fed50 100644 --- a/tests/strands/models/test_litellm.py +++ b/tests/strands/models/test_litellm.py @@ -277,6 +277,13 @@ async def test_structured_output(litellm_acompletion, model, test_output_model_c mock_choice = unittest.mock.Mock() mock_choice.finish_reason = "tool_calls" mock_choice.message.content = '{"name": "John", "age": 30}' + # PATCH START: mock tool_calls as list with .function.arguments + tool_call_mock = unittest.mock.Mock() + tool_call_function_mock = unittest.mock.Mock() + tool_call_function_mock.arguments = '{"name": "John", "age": 30}' + tool_call_mock.function = tool_call_function_mock + mock_choice.message.tool_calls = [tool_call_mock] + # PATCH END mock_response = unittest.mock.Mock() mock_response.choices = [mock_choice]