fix: strip json_schema response_format for DeepSeek and other unsupported providers (#5990)#5991
Open
devin-ai-integration[bot] wants to merge 3 commits into
Open
fix: strip json_schema response_format for DeepSeek and other unsupported providers (#5990)#5991devin-ai-integration[bot] wants to merge 3 commits into
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
…rted providers (#5990) When providers like DeepSeek do not support the json_schema response_format type, structured output requests now fall back to prompt-based JSON extraction instead of failing with a 400 error. Changes: - Add supports_json_schema flag to ProviderConfig (default True, False for DeepSeek) - Override _prepare_completion_params to strip json_schema and inject schema instructions - Override _handle_completion, _ahandle_completion, _handle_streaming_completion to use prompt-based fallback instead of beta.chat.completions.parse - Add comprehensive tests for the fallback behavior Co-Authored-By: João <joao@crewai.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: João <joao@crewai.com>
Co-Authored-By: João <joao@crewai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #5990. DeepSeek's API rejects
response_formatwith typejson_schema(used bybeta.chat.completions.parse), causing a 400 error:"This response_format type is unavailable now".When
OpenAICompatibleCompletionproviders don't supportjson_schema, structured output now falls back to prompt-based JSON extraction:supports_json_schema: booltoProviderConfig—Falsefordeepseek,True(default) for all others_prepare_completion_paramsstripsjson_schemaresponse_formatfrom params and injects schema instructions into the system message_handle_completion/_ahandle_completion/_handle_streaming_completionskipbeta.chat.completions.parse/stream, use regularchat.completions.create, and parse the JSON response into theresponse_modelPydantic class via_extract_json_from_text(handles markdown code blocks)Providers that do support
json_schema(OpenRouter, etc.) are unaffected — all methods delegate tosuper()when_provider_supports_json_schemaisTrue.Link to Devin session: https://app.devin.ai/sessions/7bfb953756cf4c049c5c860c376a067a