Fix Azure structured outputs to use json_object instead of json_schema #3908
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Azure structured outputs to use json_object instead of json_schema
Summary
Fixes issue #3906 where Azure models in CrewAI 1.4.1 fail with "Unsupported
response_format{'type': 'json_schema', 'json_schema': {...}}" error when using structured outputs.Root Cause: Azure AI Inference SDK doesn't support the
json_schemaresponse_format type that was being sent.Solution: Changed Azure completion to use
{"type": "json_object"}instead, which prompts the model to return JSON that is then validated client-side using the existing Pydantic validation logic in_handle_completion.Changes:
AzureCompletion._prepare_completion_params()to usejson_objectformat instead ofjson_schemaReview & Testing Checklist for Human
Risk Level: Yellow - Core functionality change with limited local testing
{"type": "json_object"}- I couldn't test this locally due to environment issues. The fix assumes Azure SDK supports this format. Test with a real Azure deployment to confirm it doesn't error.Test Plan
Notes
_handle_completion(lines 393-411), so the fix leverages existing infrastructure.stream=True) does not currently support structured outputs - this is a pre-existing limitation, not introduced by this PR.