Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/strands/models/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions tests/strands/models/test_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down