question_classifier return [openai_api_compatible] Error: API request failed with status code 400 #12738

Closed
opened 2026-02-21 19:08:47 -05:00 by yindo · 3 comments
Owner

Originally created by @fairyto2 on GitHub (Apr 10, 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.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When launching qwen2.5 with vllm and using the question classifier in chatflow, debugging shows an error: "[openai_api_compatible] Error: API request failed with status code 400".

Using tcpdump to capture packets, I found that there are two consecutive "user" messages in the request, causing the error.

{
    "model": "TopASK",
    "stream": true,
    "temperature": 0.7,
    "messages": [
        {
            "role": "system",
            "content": "\n    ### Job Description',\n    You are a text classification engine that analyzes text data and assigns categories based on user input or automatically determined categories.\n    ### Task\n    Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output. Additionally, you need to extract the key words from the text that are related to the classification.\n    ### Format\n    The input text is in the variable input_text. Categories are specified as a category list with two filed category_id and category_name in the variable categories. Classification instructions may be included to improve the classification accuracy.\n    ### Constraint\n    DO NOT include anything other than the JSON array in your response.\n    ### Memory\n    Here are the chat histories between human and assistant, inside <histories></histories> XML tags.\n    <histories>\n    \n    </histories>\n"
        },
        {
            "role": "user",
            "content": "\n    { \"input_text\": [\"I recently had a great experience with your company. The service was prompt and the staff was very friendly.\"],\n    \"categories\": [{\"category_id\":\"f5660049-284f-41a7-b301-fd24176a711c\",\"category_name\":\"Customer Service\"},{\"category_id\":\"8d007d06-f2c9-4be5-8ff6-cd4381c13c60\",\"category_name\":\"Satisfaction\"},{\"category_id\":\"5fbbbb18-9843-466d-9b8e-b9bfbb9482c8\",\"category_name\":\"Sales\"},{\"category_id\":\"23623c75-7184-4a2e-8226-466c2e4631e4\",\"category_name\":\"Product\"}],\n    \"classification_instructions\": [\"classify the text based on the feedback provided by customer\"]}\n"
        },
        {
            "role": "assistant",
            "content": "\n```json\n    {\"keywords\": [\"recently\", \"great experience\", \"company\", \"service\", \"prompt\", \"staff\", \"friendly\"],\n    \"category_id\": \"f5660049-284f-41a7-b301-fd24176a711c\",\n    \"category_name\": \"Customer Service\"}\n```\n"
        },
        {
            "role": "user",
            "content": "\n    {\"input_text\": [\"bad service, slow to bring the food\"],\n    \"categories\": [{\"category_id\":\"80fb86a0-4454-4bf5-924c-f253fdd83c02\",\"category_name\":\"Food Quality\"},{\"category_id\":\"f6ff5bc3-aca0-4e4a-8627-e760d0aca78f\",\"category_name\":\"Experience\"},{\"category_id\":\"cc771f63-74e7-4c61-882e-3eda9d8ba5d7\",\"category_name\":\"Price\"}],\n    \"classification_instructions\": []}\n"
        },
        {
            "role": "assistant",
            "content": "\n```json\n    {\"keywords\": [\"bad service\", \"slow\", \"food\", \"tip\", \"terrible\", \"waitresses\"],\n    \"category_id\": \"f6ff5bc3-aca0-4e4a-8627-e760d0aca78f\",\n    \"category_name\": \"Experience\"}\n```\n"
        },
        {
            "role": "user",
            "content": "\n    '{\"input_text\": [\"\u4f60\u597d\"],',\n    '\"categories\": [{\"category_id\": \"1\", \"category_name\": \"\u63a5\u53e3\u77e5\u8bc6\"}, {\"category_id\": \"2\", \"category_name\": \"\u529f\u80fd\u4f7f\u7528\"}], ',\n    '\"classification_instructions\": [\"\"]}'\n"
        },
        {
            "role": "user",
            "content": "\u4f60\u597d"
        }
    ],
    "user": "a58caa8e-6588-49f1-bcd7-3c35b8f78c1e"
}

The issue was traced to insufficiently strict condition checks in the def_fetch_prompt_messages function.

Image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @fairyto2 on GitHub (Apr 10, 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.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce When launching qwen2.5 with vllm and using the question classifier in chatflow, debugging shows an error: "[openai_api_compatible] Error: API request failed with status code 400". Using tcpdump to capture packets, I found that there are two consecutive "user" messages in the request, causing the error. ``` JSON { "model": "TopASK", "stream": true, "temperature": 0.7, "messages": [ { "role": "system", "content": "\n ### Job Description',\n You are a text classification engine that analyzes text data and assigns categories based on user input or automatically determined categories.\n ### Task\n Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output. Additionally, you need to extract the key words from the text that are related to the classification.\n ### Format\n The input text is in the variable input_text. Categories are specified as a category list with two filed category_id and category_name in the variable categories. Classification instructions may be included to improve the classification accuracy.\n ### Constraint\n DO NOT include anything other than the JSON array in your response.\n ### Memory\n Here are the chat histories between human and assistant, inside <histories></histories> XML tags.\n <histories>\n \n </histories>\n" }, { "role": "user", "content": "\n { \"input_text\": [\"I recently had a great experience with your company. The service was prompt and the staff was very friendly.\"],\n \"categories\": [{\"category_id\":\"f5660049-284f-41a7-b301-fd24176a711c\",\"category_name\":\"Customer Service\"},{\"category_id\":\"8d007d06-f2c9-4be5-8ff6-cd4381c13c60\",\"category_name\":\"Satisfaction\"},{\"category_id\":\"5fbbbb18-9843-466d-9b8e-b9bfbb9482c8\",\"category_name\":\"Sales\"},{\"category_id\":\"23623c75-7184-4a2e-8226-466c2e4631e4\",\"category_name\":\"Product\"}],\n \"classification_instructions\": [\"classify the text based on the feedback provided by customer\"]}\n" }, { "role": "assistant", "content": "\n```json\n {\"keywords\": [\"recently\", \"great experience\", \"company\", \"service\", \"prompt\", \"staff\", \"friendly\"],\n \"category_id\": \"f5660049-284f-41a7-b301-fd24176a711c\",\n \"category_name\": \"Customer Service\"}\n```\n" }, { "role": "user", "content": "\n {\"input_text\": [\"bad service, slow to bring the food\"],\n \"categories\": [{\"category_id\":\"80fb86a0-4454-4bf5-924c-f253fdd83c02\",\"category_name\":\"Food Quality\"},{\"category_id\":\"f6ff5bc3-aca0-4e4a-8627-e760d0aca78f\",\"category_name\":\"Experience\"},{\"category_id\":\"cc771f63-74e7-4c61-882e-3eda9d8ba5d7\",\"category_name\":\"Price\"}],\n \"classification_instructions\": []}\n" }, { "role": "assistant", "content": "\n```json\n {\"keywords\": [\"bad service\", \"slow\", \"food\", \"tip\", \"terrible\", \"waitresses\"],\n \"category_id\": \"f6ff5bc3-aca0-4e4a-8627-e760d0aca78f\",\n \"category_name\": \"Experience\"}\n```\n" }, { "role": "user", "content": "\n '{\"input_text\": [\"\u4f60\u597d\"],',\n '\"categories\": [{\"category_id\": \"1\", \"category_name\": \"\u63a5\u53e3\u77e5\u8bc6\"}, {\"category_id\": \"2\", \"category_name\": \"\u529f\u80fd\u4f7f\u7528\"}], ',\n '\"classification_instructions\": [\"\"]}'\n" }, { "role": "user", "content": "\u4f60\u597d" } ], "user": "a58caa8e-6588-49f1-bcd7-3c35b8f78c1e" } ``` The issue was traced to insufficiently strict condition checks in the def_fetch_prompt_messages function. ![Image](https://github.com/user-attachments/assets/3a873b33-3a43-4781-ad56-82cdbee92f5a) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 19:08:47 -05:00
yindo closed this issue 2026-02-21 19:08:47 -05:00
Author
Owner

@crazywoola commented on GitHub (Apr 10, 2025):

This is fixed in later version. Please upgrade to the latest version instead.

@crazywoola commented on GitHub (Apr 10, 2025): This is fixed in later version. Please upgrade to the latest version instead.
Author
Owner

@fairyto2 commented on GitHub (Apr 10, 2025):

@crazywoola which version?

@fairyto2 commented on GitHub (Apr 10, 2025): @crazywoola which version?
Author
Owner

@crazywoola commented on GitHub (Apr 25, 2025):

@fairyto2 Sorry I should be misremembering this, you can follow this https://github.com/langgenius/dify/issues/18810

@crazywoola commented on GitHub (Apr 25, 2025): @fairyto2 Sorry I should be misremembering this, you can follow this https://github.com/langgenius/dify/issues/18810
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12738