Skip to content

fix: skip response_format for Deepseek (provider doesn't support it)#6171

Open
tcconnally wants to merge 2 commits into
crewAIInc:mainfrom
Perseus-Computing-LLC:fix/deepseek-response-format-v2
Open

fix: skip response_format for Deepseek (provider doesn't support it)#6171
tcconnally wants to merge 2 commits into
crewAIInc:mainfrom
Perseus-Computing-LLC:fix/deepseek-response-format-v2

Conversation

@tcconnally

@tcconnally tcconnally commented Jun 15, 2026

Copy link
Copy Markdown

Problem

When using CrewAI with Deepseek, the API returns:

ERROR: 'response_format type is unavailable now'

Deepseek's API does not support OpenAI's response_format parameter. While llm.py has a supports_response_schema check (via LiteLLM), the native OpenAI completion handler in openai/completion.py adds response_format unconditionally.

Fix

Two changes:

  1. base_llm.py: Added PROVIDERS_WITHOUT_RESPONSE_FORMAT constant
  2. openai/completion.py: Gate the response_format parameter on the provider check

Before

if self.response_format is not None:
    params["response_format"] = ...

After

if (
    self.response_format is not None
    and self._extract_provider(self.model)
    not in {"deepseek"}
):
    params["response_format"] = ...

Closes #5990

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with LLM providers that don’t support response_format (notably DeepSeek). The system now applies response_format only when the selected provider supports it, avoiding errors and improving stability when using alternative model providers.

Deepseek's API returns 'response_format type is unavailable now'
when the response_format parameter is included. Added a provider
blocklist check in both base_llm.py (constant) and
openai/completion.py (gate).

Closes crewAIInc#5990
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b8554eda-76cc-427b-a159-589bef30bb8e

📥 Commits

Reviewing files that changed from the base of the PR and between f836370 and 738051d.

📒 Files selected for processing (1)
  • lib/crewai/src/crewai/llms/providers/openai/completion.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/crewai/src/crewai/llms/providers/openai/completion.py

📝 Walkthrough

Walkthrough

A new module-level constant PROVIDERS_WITHOUT_RESPONSE_FORMAT = {"deepseek"} is added to base_llm.py. OpenAICompletion._prepare_completion_params imports this constant and wraps the params["response_format"] assignment in a conditional that skips it when the extracted provider is in that set.

Changes

DeepSeek response_format guard

Layer / File(s) Summary
response_format provider constant and conditional guard
lib/crewai/src/crewai/llms/base_llm.py, lib/crewai/src/crewai/llms/providers/openai/completion.py
PROVIDERS_WITHOUT_RESPONSE_FORMAT set is declared with {"deepseek"}; _prepare_completion_params imports and checks this set so DeepSeek requests omit the response_format parameter.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 A rabbit hops past DeepSeek's gate,
Knowing response_format won't cooperate.
A tidy set, a simple check,
Keeps 400 errors off the deck.
No more crashes, smooth as clover —
The bug, at last, is finally over! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: skip response_format for Deepseek (provider doesn't support it)' clearly and concisely describes the main change: conditionally skipping the response_format parameter for Deepseek due to API incompatibility.
Linked Issues check ✅ Passed The pull request fully addresses issue #5990 by implementing conditional response_format handling for Deepseek, preventing the 400 API error and allowing CrewAI to work with Deepseek's LLM service.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective: adding a provider blocklist constant and modifying the OpenAI completion handler to respect it for Deepseek compatibility.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/crewai/src/crewai/llms/base_llm.py`:
- Around line 129-131: The completion.py file uses a hardcoded {"deepseek"}
literal to check if a provider supports response_format, instead of importing
and using the PROVIDERS_WITHOUT_RESPONSE_FORMAT constant already defined in
base_llm.py. To fix this, add an import statement for
PROVIDERS_WITHOUT_RESPONSE_FORMAT from the base_llm module into completion.py,
then replace the hardcoded {"deepseek"} set literal in the provider check logic
with the imported PROVIDERS_WITHOUT_RESPONSE_FORMAT constant to eliminate
duplication and centralize the provider blocklist.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 708376cb-d6b0-4a1c-9a9b-8a3875b4b02f

📥 Commits

Reviewing files that changed from the base of the PR and between a5cc6f6 and f836370.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/llms/base_llm.py
  • lib/crewai/src/crewai/llms/providers/openai/completion.py

Comment thread lib/crewai/src/crewai/llms/base_llm.py
Addresses CodeRabbit review: import the centralized provider blocklist
instead of duplicating a hardcoded set literal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

1 participant