Node 代码执行 run failed: The length of output variable result must be less than 30 elements. #4188

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

Originally created by @chenj133 on GitHub (Jun 20, 2024).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

Provide a description of requested docs changes

image
工作流编排中设置输出变量为Array[object],实际输出长度过长时会报错
image
请问30这个参数在哪修改让他不限制

Originally created by @chenj133 on GitHub (Jun 20, 2024). ### Self Checks - [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 report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Please do not modify this template :) and fill in all the required fields. ### Provide a description of requested docs changes ![image](https://github.com/langgenius/dify/assets/55866399/d1aa7d51-ea85-4243-b1a7-bf831da5355c) 工作流编排中设置输出变量为Array[object],实际输出长度过长时会报错 ![image](https://github.com/langgenius/dify/assets/55866399/8764dec0-0a4c-4160-bc4b-80d26af7937e) 请问30这个参数在哪修改让他不限制
yindo added the 📚 documentation label 2026-02-21 18:05:07 -05:00
yindo closed this issue 2026-02-21 18:05:07 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 20, 2024):

Hello, @chenj133! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together! 🤖

To modify the parameter that enforces the 30-element limit on the output variable result, you need to adjust the environment variables CODE_MAX_STRING_ARRAY_LENGTH and CODE_MAX_OBJECT_ARRAY_LENGTH.

These variables are defined in the code as follows:

MAX_STRING_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_STRING_ARRAY_LENGTH', '30'))
MAX_OBJECT_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_OBJECT_ARRAY_LENGTH', '30'))

You can set these environment variables to a higher value or remove the limit by setting them to a very high number. For example, you can set these variables in your environment before running your Node script:

export CODE_MAX_STRING_ARRAY_LENGTH=100
export CODE_MAX_OBJECT_ARRAY_LENGTH=100

Or you can set them directly in your script:

import os

os.environ['CODE_MAX_STRING_ARRAY_LENGTH'] = '100'
os.environ['CODE_MAX_OBJECT_ARRAY_LENGTH'] = '100'

This will increase the limit to 100 elements for both string arrays and object arrays. Adjust the values as needed [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 20, 2024): <!-- Greeting --> Hello, @chenj133! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together! 🤖 <!-- Answer --> To modify the parameter that enforces the 30-element limit on the output variable `result`, you need to adjust the environment variables `CODE_MAX_STRING_ARRAY_LENGTH` and `CODE_MAX_OBJECT_ARRAY_LENGTH`. These variables are defined in the code as follows: ```python MAX_STRING_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_STRING_ARRAY_LENGTH', '30')) MAX_OBJECT_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_OBJECT_ARRAY_LENGTH', '30')) ``` You can set these environment variables to a higher value or remove the limit by setting them to a very high number. For example, you can set these variables in your environment before running your Node script: ```sh export CODE_MAX_STRING_ARRAY_LENGTH=100 export CODE_MAX_OBJECT_ARRAY_LENGTH=100 ``` Or you can set them directly in your script: ```python import os os.environ['CODE_MAX_STRING_ARRAY_LENGTH'] = '100' os.environ['CODE_MAX_OBJECT_ARRAY_LENGTH'] = '100' ``` This will increase the limit to 100 elements for both string arrays and object arrays. Adjust the values as needed <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/code/code_node.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@chenj133 commented on GitHub (Jun 20, 2024):

Hello, @chenj133! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together! 🤖

To modify the parameter that enforces the 30-element limit on the output variable result, you need to adjust the environment variables CODE_MAX_STRING_ARRAY_LENGTH and CODE_MAX_OBJECT_ARRAY_LENGTH.

These variables are defined in the code as follows:

MAX_STRING_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_STRING_ARRAY_LENGTH', '30'))
MAX_OBJECT_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_OBJECT_ARRAY_LENGTH', '30'))

You can set these environment variables to a higher value or remove the limit by setting them to a very high number. For example, you can set these variables in your environment before running your Node script:

export CODE_MAX_STRING_ARRAY_LENGTH=100
export CODE_MAX_OBJECT_ARRAY_LENGTH=100

Or you can set them directly in your script:

import os

os.environ['CODE_MAX_STRING_ARRAY_LENGTH'] = '100'
os.environ['CODE_MAX_OBJECT_ARRAY_LENGTH'] = '100'

This will increase the limit to 100 elements for both string arrays and object arrays. Adjust the values as needed [1].

To continue talking to Dosu, mention @dosu.

Thanks for your replay.
I set the env in script like this:
image
but it still error:
image
maybe I should set it outsite?

@chenj133 commented on GitHub (Jun 20, 2024): > Hello, @chenj133! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together! 🤖 > > To modify the parameter that enforces the 30-element limit on the output variable `result`, you need to adjust the environment variables `CODE_MAX_STRING_ARRAY_LENGTH` and `CODE_MAX_OBJECT_ARRAY_LENGTH`. > > These variables are defined in the code as follows: > > ```python > MAX_STRING_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_STRING_ARRAY_LENGTH', '30')) > MAX_OBJECT_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_OBJECT_ARRAY_LENGTH', '30')) > ``` > > You can set these environment variables to a higher value or remove the limit by setting them to a very high number. For example, you can set these variables in your environment before running your Node script: > > ```shell > export CODE_MAX_STRING_ARRAY_LENGTH=100 > export CODE_MAX_OBJECT_ARRAY_LENGTH=100 > ``` > > Or you can set them directly in your script: > > ```python > import os > > os.environ['CODE_MAX_STRING_ARRAY_LENGTH'] = '100' > os.environ['CODE_MAX_OBJECT_ARRAY_LENGTH'] = '100' > ``` > > This will increase the limit to 100 elements for both string arrays and object arrays. Adjust the values as needed [[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/code/code_node.py). > > _To continue talking to [Dosu](https://dosu.dev), mention @dosu._ Thanks for your replay. I set the env in script like this: ![image](https://github.com/langgenius/dify/assets/55866399/41cc19f7-0a2e-4f61-96f4-60b88c6c74bd) but it still error: ![image](https://github.com/langgenius/dify/assets/55866399/e1424c10-8ec1-41fc-af36-e255cb5ae1a0) maybe I should set it outsite?
Author
Owner

@chenj133 commented on GitHub (Jun 20, 2024):

I change the environment on docker compose yaml and it works, thanks

@chenj133 commented on GitHub (Jun 20, 2024): I change the environment on docker compose yaml and it works, thanks
Author
Owner

@Sakura4036 commented on GitHub (Jun 21, 2024):

Modify .env file if you launch dify with souce code:

cd dify/api
cp .env.example .env
vi .env

Then modify the environment variables in the CODE EXECUTION CONFIGURATION section, for example:
image

If you are using docker to start, modify the corresponding environment variables in the api in the docke-compse.yaml file: CODE_MAX_STRING_ARRAY_LENGTH, CODE_MAX_OBJECT_ARRAY_LENGTH, CODE_MAX_NUMBER_ARRAY_LENGTH
image

@Sakura4036 commented on GitHub (Jun 21, 2024): Modify `.env` file if you launch dify with souce code: ```shell cd dify/api cp .env.example .env vi .env ``` Then modify the environment variables in the CODE EXECUTION CONFIGURATION section, for example: ![image](https://github.com/langgenius/dify/assets/42060616/d962c241-349a-47c3-af6e-a84d9f30aa2b) If you are using docker to start, modify the corresponding environment variables in the api in the docke-compse.yaml file: `CODE_MAX_STRING_ARRAY_LENGTH`, `CODE_MAX_OBJECT_ARRAY_LENGTH`, `CODE_MAX_NUMBER_ARRAY_LENGTH` ![image](https://github.com/langgenius/dify/assets/42060616/749e6e9d-2c14-4d37-9388-b30434b05c87)
Author
Owner

@hzho2000 commented on GitHub (Aug 24, 2024):

I change the environment on docker compose yaml and it works, thanks

你好,我修改了Docker Compose的yaml文件,但是似乎没有应用成功。还是30的限制。我试图删除了容器和镜像,并重新compose仍然如此。并且奇怪的是第二次安装时也没有初始化的状态了。所以想请教一下修改了配置文件后,如何重新加载。

Hello, I modified the Docker Compose yaml file, but it doesn't seem to have taken effect. The limit is still 30. I tried deleting the containers and images, and then re-running compose, but the issue persists. What's strange is that the second time I installed, there was no initialization phase anymore. Could you please advise on how to reload the configuration after modifying the yaml file?

@hzho2000 commented on GitHub (Aug 24, 2024): > I change the environment on docker compose yaml and it works, thanks 你好,我修改了Docker Compose的yaml文件,但是似乎没有应用成功。还是30的限制。我试图删除了容器和镜像,并重新compose仍然如此。并且奇怪的是第二次安装时也没有初始化的状态了。所以想请教一下修改了配置文件后,如何重新加载。 Hello, I modified the Docker Compose yaml file, but it doesn't seem to have taken effect. The limit is still 30. I tried deleting the containers and images, and then re-running compose, but the issue persists. What's strange is that the second time I installed, there was no initialization phase anymore. Could you please advise on how to reload the configuration after modifying the yaml file?
Author
Owner

@jeffsmish commented on GitHub (Feb 5, 2025):

I change the environment on docker compose yaml and it works, thanks我更改了 docker compose yaml 上的环境并且它有效,谢谢

你好,我修改了Docker Compose的yaml文件,但是似乎没有应用成功。还是30的限制。我试图删除了容器和镜像,并重新compose仍然如此。并且奇怪的是第二次安装时也没有初始化的状态了。所以想请教一下修改了配置文件后,如何重新加载。

Hello, I modified the Docker Compose yaml file, but it doesn't seem to have taken effect. The limit is still 30. I tried deleting the containers and images, and then re-running compose, but the issue persists. What's strange is that the second time I installed, there was no initialization phase anymore. Could you please advise on how to reload the configuration after modifying the yaml file?您好,我修改了Docker Compose yaml文件,但是好像没有生效。限制仍然是 30。我尝试删除容器和图像,然后重新运行 compose,但问题仍然存在。奇怪的是,我第二次安装的时候,就没有初始化阶段了。请问修改yaml文件后如何重新加载配置?

直接修改.env文件中的变量试试

@jeffsmish commented on GitHub (Feb 5, 2025): > > I change the environment on docker compose yaml and it works, thanks我更改了 docker compose yaml 上的环境并且它有效,谢谢 > > 你好,我修改了Docker Compose的yaml文件,但是似乎没有应用成功。还是30的限制。我试图删除了容器和镜像,并重新compose仍然如此。并且奇怪的是第二次安装时也没有初始化的状态了。所以想请教一下修改了配置文件后,如何重新加载。 > > Hello, I modified the Docker Compose yaml file, but it doesn't seem to have taken effect. The limit is still 30. I tried deleting the containers and images, and then re-running compose, but the issue persists. What's strange is that the second time I installed, there was no initialization phase anymore. Could you please advise on how to reload the configuration after modifying the yaml file?您好,我修改了Docker Compose yaml文件,但是好像没有生效。限制仍然是 30。我尝试删除容器和图像,然后重新运行 compose,但问题仍然存在。奇怪的是,我第二次安装的时候,就没有初始化阶段了。请问修改yaml文件后如何重新加载配置? 直接修改.env文件中的变量试试
Author
Owner

@lzpsqzr commented on GitHub (Aug 14, 2025):

Hello,

I am using enterprise version which deployed by enterprice-helm-2.8.0 from here https://langgenius.github.io/dify-helm/ , I have the same issue, I tried to modify the env of sandbox by setting :

sandbox:
  enabled: true
  extraEnv: 
    - name: CODE_MAX_STRING_ARRAY_LENGTH
      value: "5000"
    - name: CODE_MAX_OBJECT_ARRAY_LENGTH
      value: "5000"

but seems it is still limiting 30 elements, did I set in the right component?

@lzpsqzr commented on GitHub (Aug 14, 2025): Hello, I am using enterprise version which deployed by enterprice-helm-2.8.0 from here https://langgenius.github.io/dify-helm/ , I have the same issue, I tried to modify the env of sandbox by setting : ``` sandbox: enabled: true extraEnv: - name: CODE_MAX_STRING_ARRAY_LENGTH value: "5000" - name: CODE_MAX_OBJECT_ARRAY_LENGTH value: "5000" ``` but seems it is still limiting 30 elements, did I set in the right component?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4188