From 8f69ecbb52a26a022c2e19f419359b9ea6bb8257 Mon Sep 17 00:00:00 2001 From: Vlad Riabchenko Date: Wed, 16 Jul 2025 16:18:51 +0200 Subject: [PATCH] fix: Remove finish_reason from structured_output in LiteLLMModel --- src/strands/models/litellm.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/strands/models/litellm.py b/src/strands/models/litellm.py index c1e99f1a2..f223f80d3 100644 --- a/src/strands/models/litellm.py +++ b/src/strands/models/litellm.py @@ -209,17 +209,15 @@ async def structured_output( if len(response.choices) > 1: raise ValueError("Multiple choices found in the response.") - # Find the first choice with tool_calls for choice in response.choices: - if choice.finish_reason == "tool_calls": - try: - # Parse the tool call content as JSON - tool_call_data = json.loads(choice.message.content) - # Instantiate the output model with the parsed data - yield {"output": output_model(**tool_call_data)} - return - except (json.JSONDecodeError, TypeError, ValueError) as e: - raise ValueError(f"Failed to parse or load content into model: {e}") from e - - # If no tool_calls found, raise an error - raise ValueError("No tool_calls found in response") + try: + # Parse the message content as JSON + output_data = json.loads(choice.message.content) + # Instantiate the output model with the parsed data + yield {"output": output_model(**output_data)} + return + except (json.JSONDecodeError, TypeError, ValueError) as e: + raise ValueError(f"Failed to parse or load content into model: {e}") from e + + # If no choices found, raise an error + raise ValueError("No choices found in response")