Skip to content

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
mainfrom
fix/5990-deepseek-response-format
Open

fix: strip json_schema response_format for DeepSeek and other unsupported providers (#5990)#5991
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
fix/5990-deepseek-response-format

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Fixes #5990. DeepSeek's API rejects response_format with type json_schema (used by beta.chat.completions.parse), causing a 400 error: "This response_format type is unavailable now".

When OpenAICompatibleCompletion providers don't support json_schema, structured output now falls back to prompt-based JSON extraction:

  • Added supports_json_schema: bool to ProviderConfigFalse for deepseek, True (default) for all others
  • _prepare_completion_params strips json_schema response_format from params and injects schema instructions into the system message
  • _handle_completion / _ahandle_completion / _handle_streaming_completion skip beta.chat.completions.parse/stream, use regular chat.completions.create, and parse the JSON response into the response_model Pydantic class via _extract_json_from_text (handles markdown code blocks)

Providers that do support json_schema (OpenRouter, etc.) are unaffected — all methods delegate to super() when _provider_supports_json_schema is True.

Link to Devin session: https://app.devin.ai/sessions/7bfb953756cf4c049c5c860c376a067a

…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>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Co-Authored-By: João <joao@crewai.com>
import json
import os
from unittest.mock import patch
from unittest.mock import AsyncMock, MagicMock, patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OpenAI API call fails with "response_format type is unavailable now" when using Deepseek

0 participants