Get a "list index out of range" error when enable chat history in CHATFLOW. #8943

Closed
opened 2026-02-21 18:28:46 -05:00 by yindo · 3 comments
Owner

Originally created by @github0null on GitHub (Mar 3, 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

1.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Repeat steps

First. Create an chatflow app.

Image

Second. Select a completion model (Not a chat model !), then enable MEMORY option and insert history tag into prompt.

Image

Image

Then, type something and start the chat flow, it's not work.

An error has occurred:

Run failed: PluginInvokeError: {"args":{},"error_type":"IndexError","message":"list index out of range"}

Image

Once I disable the MEMORY button, it works (of course, the history was missed)

I am deployed using docker containers, and I have checked the logs of docker containers (docker_api, docker_web, docker_worker) and found nothing valuable infomations.

And this problem also existed in the previous version: v0.15.3.

I know I can get around this by using a chat model, but I wanted to report it anyway. I'm not sure if there's something wrong with my usage.

✔️ Expected Behavior

No error. It works.

Actual Behavior

An error has occurred:

Run failed: PluginInvokeError: {"args":{},"error_type":"IndexError","message":"list index out of range"}
Originally created by @github0null on GitHub (Mar 3, 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 1.0.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ## Repeat steps First. Create an chatflow app. ![Image](https://github.com/user-attachments/assets/c26053bb-3665-41cb-ba10-7ad65508a935) Second. Select a completion model (Not a chat model !), then enable `MEMORY` option and insert history tag into prompt. ![Image](https://github.com/user-attachments/assets/06d3e78d-df5c-4e28-8e2a-9840e18c62bd) ![Image](https://github.com/user-attachments/assets/2f3569a1-f465-4ff7-8c4e-f1768f8fb8c3) Then, type something and start the chat flow, it's not work. An error has occurred: ``` Run failed: PluginInvokeError: {"args":{},"error_type":"IndexError","message":"list index out of range"} ``` ![Image](https://github.com/user-attachments/assets/84666b22-e6da-4b19-8f3d-4433c3da6b39) Once I disable the `MEMORY` button, it works (of course, the history was missed) I am deployed using docker containers, and I have checked the logs of docker containers (docker_api, docker_web, docker_worker) and found nothing valuable infomations. And this problem also existed in the previous version: v0.15.3. I know I can get around this by using a chat model, but I wanted to report it anyway. I'm not sure if there's something wrong with my usage. ### ✔️ Expected Behavior No error. It works. ### ❌ Actual Behavior An error has occurred: ``` Run failed: PluginInvokeError: {"args":{},"error_type":"IndexError","message":"list index out of range"} ```
yindo added the 🐞 bug label 2026-02-21 18:28:46 -05:00
yindo closed this issue 2026-02-21 18:28:46 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 3, 2025):

Hello, @github0null! I'm here to help you with any bugs, questions, or contributions you have for CHATFLOW. Let's tackle this issue together!

To resolve the "list index out of range" error when enabling chat history in CHATFLOW using the completion model with the MEMORY option, ensure that the prompt_messages list is not empty before accessing prompt_messages[0].content. You can add a check to verify that prompt_messages contains at least one element:

# Ensure prompt_messages is not empty
if prompt_messages:
    # Insert histories into the prompt
    prompt_content = prompt_messages[0].content
    # For issue #11247 - Check if prompt content is a string or a list
    prompt_content_type = type(prompt_content)
    if prompt_content_type == str:
        if "#histories#" in prompt_content:
            prompt_content = prompt_content.replace("#histories#", memory_text)
        else:
            prompt_content = memory_text + "\n" + prompt_content
        prompt_messages[0].content = prompt_content
    elif prompt_content_type == list:
        for content_item in prompt_content:
            if content_item.type == PromptMessageContentType.TEXT:
                if "#histories#" in content_item.data:
                    content_item.data = content_item.data.replace("#histories#", memory_text)
                else:
                    content_item.data = memory_text + "\n" + content_item.data
    else:
        raise ValueError("Invalid prompt content type")
else:
    raise IndexError("prompt_messages list is empty")

This check will prevent the "list index out of range" error by ensuring that the list is not empty before attempting to access its elements [1].

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (Mar 3, 2025): <!-- Greeting --> Hello, @github0null! I'm here to help you with any bugs, questions, or contributions you have for CHATFLOW. Let's tackle this issue together! <!-- Answer --> To resolve the "list index out of range" error when enabling chat history in CHATFLOW using the completion model with the MEMORY option, ensure that the `prompt_messages` list is not empty before accessing `prompt_messages[0].content`. You can add a check to verify that `prompt_messages` contains at least one element: ```python # Ensure prompt_messages is not empty if prompt_messages: # Insert histories into the prompt prompt_content = prompt_messages[0].content # For issue #11247 - Check if prompt content is a string or a list prompt_content_type = type(prompt_content) if prompt_content_type == str: if "#histories#" in prompt_content: prompt_content = prompt_content.replace("#histories#", memory_text) else: prompt_content = memory_text + "\n" + prompt_content prompt_messages[0].content = prompt_content elif prompt_content_type == list: for content_item in prompt_content: if content_item.type == PromptMessageContentType.TEXT: if "#histories#" in content_item.data: content_item.data = content_item.data.replace("#histories#", memory_text) else: content_item.data = memory_text + "\n" + content_item.data else: raise ValueError("Invalid prompt content type") else: raise IndexError("prompt_messages list is empty") ``` This check will prevent the "list index out of range" error by ensuring that the list is not empty before attempting to access its elements <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/llm/node.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/52df8948-c2c9-4edb-a296-4c25ffe305d4?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/52df8948-c2c9-4edb-a296-4c25ffe305d4?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/52df8948-c2c9-4edb-a296-4c25ffe305d4?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/52df8948-c2c9-4edb-a296-4c25ffe305d4?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/52df8948-c2c9-4edb-a296-4c25ffe305d4?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/52df8948-c2c9-4edb-a296-4c25ffe305d4?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/52df8948-c2c9-4edb-a296-4c25ffe305d4?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Mar 3, 2025):

Will take a look at it later.

@crazywoola commented on GitHub (Mar 3, 2025): Will take a look at it later.
Author
Owner

@dosubot[bot] commented on GitHub (Apr 3, 2025):

Hi, @github0null. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • "List index out of range" error occurs when enabling chat history in a CHATFLOW app with the MEMORY option.
  • Error is absent when the MEMORY option is disabled.
  • Suggested solution to check the prompt_messages list was not well-received.
  • @crazywoola mentioned they would investigate the issue further.

Next Steps

  • Is this issue still relevant to the latest version of the Dify repository? If so, please comment to keep the discussion open.
  • If no further activity occurs, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Apr 3, 2025): Hi, @github0null. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. **Issue Summary** - "List index out of range" error occurs when enabling chat history in a CHATFLOW app with the `MEMORY` option. - Error is absent when the `MEMORY` option is disabled. - Suggested solution to check the `prompt_messages` list was not well-received. - @crazywoola mentioned they would investigate the issue further. **Next Steps** - Is this issue still relevant to the latest version of the Dify repository? If so, please comment to keep the discussion open. - If no further activity occurs, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8943