Claude model, error # Help after calling stop interface #310

Closed
opened 2026-02-16 10:18:56 -05:00 by yindo · 3 comments
Owner

Originally created by @13261046907 on GitHub (May 26, 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

Version 1.4.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Claude model error:
When the message is outputting normally and the stop interface is successfully called, asking the question again will result in an error
Image

✔️ Expected Behavior

Return result without error, answer normally

Actual Behavior

1、Error as shown in the figure:
Image
2、Interface call returns error:
{"event": "error", "conversation_id": "760ea5ea-f92b-441e-92f5-2eef114bef1e", "message_id": "0dadcbbe-7210-4caa-8f2e-d05dc8af87cf", "created_at": 1748232745, "code": "completion_request_error", "status": 400, "message": "[models] Bad Request Error, Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.3: all messages must have non-empty content except for the optional final assistant message'}}"}
Could you please help me with this? Thank you very much 🙏

Originally created by @13261046907 on GitHub (May 26, 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 Version 1.4.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Claude model error: When the message is outputting normally and the stop interface is successfully called, asking the question again will result in an error ![Image](https://github.com/user-attachments/assets/caa2fbf4-0aab-4f08-b756-c59da578a0ed) ### ✔️ Expected Behavior Return result without error, answer normally ### ❌ Actual Behavior 1、Error as shown in the figure: ![Image](https://github.com/user-attachments/assets/caa2fbf4-0aab-4f08-b756-c59da578a0ed) 2、Interface call returns error: {"event": "error", "conversation_id": "760ea5ea-f92b-441e-92f5-2eef114bef1e", "message_id": "0dadcbbe-7210-4caa-8f2e-d05dc8af87cf", "created_at": 1748232745, "code": "completion_request_error", "status": 400, "message": "[models] Bad Request Error, Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.3: all messages must have non-empty content except for the optional final assistant message'}}"} Could you please help me with this? Thank you very much 🙏
yindo closed this issue 2026-02-16 10:18:56 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (May 26, 2025):

Based on the information available, the error you are encountering—completion_request_error with code 400 and the message all messages must have non-empty content except for the optional final assistant message—indicates that after calling the stop interface, a subsequent request is being made where at least one message in the payload has empty content. This is not allowed by the Claude model API.

Here’s what is known:

  • The /completion-messages/{task_id}/stop endpoint is used to stop a generation task and is only supported in streaming mode. The task_id must be obtained from the streaming chunk return of a /completion-messages request. source
  • The error completion_request_error with code 400 is described as "Text generation failed" and can be triggered by invalid request parameters, including empty message content. source

What this likely means for your workflow:

  • After stopping a generation, the conversation state may be left in a way where the next request includes an empty message (possibly a placeholder or incomplete message object).
  • The Claude API requires that all messages (except the optional final assistant message) have non-empty content.

What you can try:

  • Check the payload being sent after you call the stop interface. Ensure that every message in the messages array has non-empty content.
  • If you are using custom code or middleware, verify that the conversation history is not including an empty message as a result of the stop operation.
  • If this is happening within the Dify UI or API, it may be a bug in how the conversation state is managed after a stop. In that case, you may want to review how messages are appended or cleared after stopping a generation.

Unfortunately, I was not able to find any existing documentation or previous issues in the Dify repositories that address this specific error or provide troubleshooting steps for this scenario.

If you need further assistance, providing a sample of the request payload sent after the stop operation may help in diagnosing the issue more precisely.

To continue talking to Dosu, mention @dosu-bot.


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

@dosubot[bot] commented on GitHub (May 26, 2025): <!-- Answer --> Based on the information available, the error you are encountering—`completion_request_error` with code 400 and the message `all messages must have non-empty content except for the optional final assistant message`—indicates that after calling the stop interface, a subsequent request is being made where at least one message in the payload has empty content. This is not allowed by the Claude model API. Here’s what is known: - The `/completion-messages/{task_id}/stop` endpoint is used to stop a generation task and is only supported in streaming mode. The `task_id` must be obtained from the streaming chunk return of a `/completion-messages` request. [source](https://github.com/crazywoola/dify-docs-mintlify/blob/main/en/openapi_completion.json) - The error `completion_request_error` with code 400 is described as "Text generation failed" and can be triggered by invalid request parameters, including empty message content. [source](https://github.com/crazywoola/dify-docs-mintlify/blob/main/en/guides/knowledge-base/knowledge-and-documents-maintenance/external-knowledge-api.mdx) What this likely means for your workflow: - After stopping a generation, the conversation state may be left in a way where the next request includes an empty message (possibly a placeholder or incomplete message object). - The Claude API requires that all messages (except the optional final assistant message) have non-empty content. **What you can try:** - Check the payload being sent after you call the stop interface. Ensure that every message in the `messages` array has non-empty content. - If you are using custom code or middleware, verify that the conversation history is not including an empty message as a result of the stop operation. - If this is happening within the Dify UI or API, it may be a bug in how the conversation state is managed after a stop. In that case, you may want to review how messages are appended or cleared after stopping a generation. Unfortunately, I was not able to find any existing documentation or previous issues in the Dify repositories that address this specific error or provide troubleshooting steps for this scenario. If you need further assistance, providing a sample of the request payload sent after the stop operation may help in diagnosing the issue more precisely. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://go.dosu.dev/dosubot), mention @dosu-bot.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/08baa0ea-b5b3-4950-af6e-8b1f6d5f0940?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/08baa0ea-b5b3-4950-af6e-8b1f6d5f0940?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/08baa0ea-b5b3-4950-af6e-8b1f6d5f0940?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/08baa0ea-b5b3-4950-af6e-8b1f6d5f0940?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/08baa0ea-b5b3-4950-af6e-8b1f6d5f0940?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/08baa0ea-b5b3-4950-af6e-8b1f6d5f0940?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/08baa0ea-b5b3-4950-af6e-8b1f6d5f0940?feedback_type=other)</sup>
Author
Owner

@13261046907 commented on GitHub (May 26, 2025):

Using the same code logic, no errors have occurred in other models such as gpt and deepseek. If the message is not generated after calling the stop interface, the last message must be empty. How to avoid errors when sending messages to claude again? @dosu-bot

@13261046907 commented on GitHub (May 26, 2025): Using the same code logic, no errors have occurred in other models such as gpt and deepseek. If the message is not generated after calling the stop interface, the last message must be empty. How to avoid errors when sending messages to claude again? @dosu-bot
Author
Owner

@dosubot[bot] commented on GitHub (May 26, 2025):

The error with the Claude model occurs because it enforces a stricter requirement: all messages in the payload must have non-empty content (except for the optional final assistant message). Other models like GPT and DeepSeek are more lenient and do not throw an error if the last message is empty, which is why your current logic works for them but not for Claude.

To avoid this error when sending messages to Claude after calling the stop interface, you need to ensure that the message array you send does not include any messages with empty content. Specifically:

  • Before sending a new request to Claude, check your message history array and remove any messages where the content is empty (e.g., "" or null).
  • If your logic creates a placeholder or incomplete message after stopping, make sure to filter it out or fill it with valid content before making the next request.

This adjustment should be made only for Claude, since other models do not require it. You can implement a check in your code to clean up the message array before sending it to the Claude API.

There is no configuration in Dify or the Claude model YAML that changes this behavior—it's an API-level requirement from Claude. The solution is to ensure your message payloads always have non-empty content for all messages except the optional final assistant message before making the API call.

If you need to keep the message structure consistent across models, you can add a step to sanitize the message array for Claude requests only, right before sending.

Let me know if you need an example of how to implement this check in your code.

To reply, just mention my name @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (May 26, 2025): <!-- Answer --> The error with the Claude model occurs because it enforces a stricter requirement: all messages in the payload must have non-empty content (except for the optional final assistant message). Other models like GPT and DeepSeek are more lenient and do not throw an error if the last message is empty, which is why your current logic works for them but not for Claude. To avoid this error when sending messages to Claude after calling the stop interface, you need to ensure that the message array you send does not include any messages with empty content. Specifically: - Before sending a new request to Claude, check your message history array and remove any messages where the content is empty (e.g., `""` or `null`). - If your logic creates a placeholder or incomplete message after stopping, make sure to filter it out or fill it with valid content before making the next request. This adjustment should be made only for Claude, since other models do not require it. You can implement a check in your code to clean up the message array before sending it to the Claude API. There is no configuration in Dify or the Claude model YAML that changes this behavior—it's an API-level requirement from Claude. The solution is to ensure your message payloads always have non-empty content for all messages except the optional final assistant message before making the API call. If you need to keep the message structure consistent across models, you can add a step to sanitize the message array for Claude requests only, right before sending. Let me know if you need an example of how to implement this check in your code. <!-- Dosu Comment Footer --> *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b94c9567-e659-4098-8043-d67e5e5fbfdb?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b94c9567-e659-4098-8043-d67e5e5fbfdb?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b94c9567-e659-4098-8043-d67e5e5fbfdb?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b94c9567-e659-4098-8043-d67e5e5fbfdb?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b94c9567-e659-4098-8043-d67e5e5fbfdb?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b94c9567-e659-4098-8043-d67e5e5fbfdb?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b94c9567-e659-4098-8043-d67e5e5fbfdb?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/20206)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#310