DeepSeek API Error with response format active (text and json_object) #7708

Closed
opened 2026-02-21 18:21:59 -05:00 by yindo · 7 comments
Owner

Originally created by @juniorsereno on GitHub (Jan 13, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Choose chatflow
Put a LLM node
Choose deepseek-chat
Active response format
Both text and json_object
Then we got an error

✔️ Expected Behavior

Normal response from deepseek

Actual Behavior

Run failed: [deepseek] Error: API request failed with status code 422: Failed to deserialize the JSON body into the target type: response_format.type: invalid type: map, expected variant identifier at line 1 column 152

Originally created by @juniorsereno on GitHub (Jan 13, 2025). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Choose chatflow Put a LLM node Choose deepseek-chat Active response format Both text and json_object Then we got an error ### ✔️ Expected Behavior Normal response from deepseek ### ❌ Actual Behavior Run failed: [deepseek] Error: API request failed with status code 422: Failed to deserialize the JSON body into the target type: response_format.type: invalid type: map, expected variant identifier at line 1 column 152
yindo added the 🐞 bug label 2026-02-21 18:21:59 -05:00
yindo closed this issue 2026-02-21 18:21:59 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 13, 2025):

I found a similar closed issue regarding the DeepSeek API error when using the response format. The issue was resolved by ensuring that the response_format parameter in model_parameters is correctly structured. Specifically, the response_format should be a dictionary with a key "type".

Here's the relevant code snippet that was used to fix the issue:

# {"response_format": "xx"} need convert to {"response_format": {"type": "xx"}}
if "response_format" in model_parameters:
    model_parameters["response_format"] = {"type": model_parameters.get("response_format")}

Make sure that when you set the response_format in model_parameters, it follows this structure:

model_parameters = {
    "response_format": {"type": "text"}  # or {"type": "json_object"}
}

This should help in resolving the JSON deserialization failure by ensuring the API receives the expected format [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Jan 13, 2025): <!-- Answer --> I found a similar closed issue regarding the DeepSeek API error when using the response format. The issue was resolved by ensuring that the `response_format` parameter in `model_parameters` is correctly structured. Specifically, the `response_format` should be a dictionary with a key `"type"`. Here's the relevant code snippet that was used to fix the issue: ```python # {"response_format": "xx"} need convert to {"response_format": {"type": "xx"}} if "response_format" in model_parameters: model_parameters["response_format"] = {"type": model_parameters.get("response_format")} ``` Make sure that when you set the `response_format` in `model_parameters`, it follows this structure: ```python model_parameters = { "response_format": {"type": "text"} # or {"type": "json_object"} } ``` This should help in resolving the JSON deserialization failure by ensuring the API receives the expected format <sup>[[1]](https://github.com/langgenius/dify/issues/11677)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/deepseek/llm/llm.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/b76b8224-fe83-4239-a3a1-6e37a65c66c6?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/b76b8224-fe83-4239-a3a1-6e37a65c66c6?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/b76b8224-fe83-4239-a3a1-6e37a65c66c6?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/b76b8224-fe83-4239-a3a1-6e37a65c66c6?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b76b8224-fe83-4239-a3a1-6e37a65c66c6?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/b76b8224-fe83-4239-a3a1-6e37a65c66c6?feedback_type=other)</sup>
Author
Owner

@Designerxsh commented on GitHub (Jan 13, 2025):

same problem on Dify version 0.15.0

@Designerxsh commented on GitHub (Jan 13, 2025): same problem on Dify version 0.15.0
Author
Owner

@suntao2015005848 commented on GitHub (Jan 13, 2025):

The issue has not been fixed, and the same problem persists.

@suntao2015005848 commented on GitHub (Jan 13, 2025): The issue has not been fixed, and the same problem persists.
Author
Owner

@k99k5 commented on GitHub (Jan 14, 2025):

+1

@k99k5 commented on GitHub (Jan 14, 2025): +1
Author
Owner

@AliceZ413 commented on GitHub (Jan 19, 2025):

same problem on 0.15.1

@AliceZ413 commented on GitHub (Jan 19, 2025): same problem on 0.15.1
Author
Owner

@suntao2015005848 commented on GitHub (Jan 23, 2025):

same problem on 0.15.2:

Image
@suntao2015005848 commented on GitHub (Jan 23, 2025): same problem on 0.15.2: <img width="993" alt="Image" src="https://github.com/user-attachments/assets/cc145087-de21-4e38-968d-298e3d6028c1" />
Author
Owner

@tylerdurden4285 commented on GitHub (Feb 7, 2025):

+1 same issue.

@tylerdurden4285 commented on GitHub (Feb 7, 2025): +1 same issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7708