Skip to content

Commit 104ecb5

Browse files
authored
fix(litellm): enhance structured output handling (#1021)
* fix(litellm): enhance structured output handling * fix(litellm): update logic
1 parent 49e432d commit 104ecb5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/strands/models/litellm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ async def _structured_output_using_response_schema(
266266

267267
if len(response.choices) > 1:
268268
raise ValueError("Multiple choices found in the response.")
269-
if not response.choices or response.choices[0].finish_reason != "tool_calls":
270-
raise ValueError("No tool_calls found in response")
269+
if not response.choices:
270+
raise ValueError("No choices found in response")
271271

272272
choice = response.choices[0]
273273
try:

tests/strands/models/test_litellm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ async def test_structured_output(litellm_acompletion, model, test_output_model_c
316316
mock_choice = unittest.mock.Mock()
317317
mock_choice.finish_reason = "tool_calls"
318318
mock_choice.message.content = '{"name": "John", "age": 30}'
319+
# PATCH START: mock tool_calls as list with .function.arguments
320+
tool_call_mock = unittest.mock.Mock()
321+
tool_call_function_mock = unittest.mock.Mock()
322+
tool_call_function_mock.arguments = '{"name": "John", "age": 30}'
323+
tool_call_mock.function = tool_call_function_mock
324+
mock_choice.message.tool_calls = [tool_call_mock]
325+
# PATCH END
319326
mock_response = unittest.mock.Mock()
320327
mock_response.choices = [mock_choice]
321328

0 commit comments

Comments
 (0)