diff --git a/lib/crewai/src/crewai/llms/providers/azure/completion.py b/lib/crewai/src/crewai/llms/providers/azure/completion.py index de9a79174..12a2f3a96 100644 --- a/lib/crewai/src/crewai/llms/providers/azure/completion.py +++ b/lib/crewai/src/crewai/llms/providers/azure/completion.py @@ -622,16 +622,6 @@ class AzureCompletion(BaseLLM): usage = self._extract_azure_token_usage(response) self._track_token_usage_internal(usage) - if response_model and self.is_openai_model: - content = message.content or "" - return self._validate_and_emit_structured_output( - content=content, - response_model=response_model, - params=params, - from_task=from_task, - from_agent=from_agent, - ) - # If there are tool_calls but no available_functions, return the tool_calls # This allows the caller (e.g., executor) to handle tool execution if message.tool_calls and not available_functions: @@ -674,6 +664,15 @@ class AzureCompletion(BaseLLM): # Apply stop words content = self._apply_stop_words(content) + if response_model and self.is_openai_model: + return self._validate_and_emit_structured_output( + content=content, + response_model=response_model, + params=params, + from_task=from_task, + from_agent=from_agent, + ) + # Emit completion event and return content self._emit_call_completed_event( response=content,