Consultation on the use of iteration and loop in dify #14727

Closed
opened 2026-02-21 19:18:30 -05:00 by yindo · 18 comments
Owner

Originally created by @chenxs-sx on GitHub (Jun 19, 2025).

Self Checks

  • 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.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

How should I output the iteration or loop tool in the workflow? I see that in the new version of Dify, iteration and loop no longer have a direct menu to return or end

Image

The function here is inconsistent with the description and sample pictures in the document

Is there anyone who can help me answer this question?

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @chenxs-sx on GitHub (Jun 19, 2025). ### 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 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. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. How should I output the iteration or loop tool in the workflow? I see that in the new version of Dify, iteration and loop no longer have a direct menu to return or end <img width="643" alt="Image" src="https://github.com/user-attachments/assets/55c461e1-c9c2-4198-8a11-47075b427b1b" /> The function here is inconsistent with the description and sample pictures in the document Is there anyone who can help me answer this question? ### 2. Additional context or comments _No response_ ### 3. Can you help us with this feature? - [x] I am interested in contributing to this feature.
yindo closed this issue 2026-02-21 19:18:31 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 19, 2025):

In the latest version of Dify, iteration and loop nodes have moved to a more implicit, structure-driven model. There is no longer a direct UI menu for "return" or "end" actions. Instead, completion is determined by the workflow's graph structure and node configuration—such as break conditions, loop counts, and outputs set in the configuration panels. This means the end of an iteration or loop is inferred automatically based on how you connect and configure nodes, not by a manual menu action. This change was made to improve consistency and robustness in workflow execution, but it does mean the UI and documentation may be out of sync right now [source].

For configuring iteration and loop nodes: you can set up parallel execution, error handling modes (terminate, continue on error, or remove abnormal output), loop variables, break conditions, and loop counts directly in the node panels. The backend now manages the orchestration, and the frontend focuses on configuration and visualization [iteration node code] [loop node code].

If you want to contribute, updating the documentation or UI hints to reflect this new implicit model would be very helpful for other users. Let me know if you want more technical details or examples for a specific workflow scenario!

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jun 19, 2025): <!-- Answer --> In the latest version of Dify, iteration and loop nodes have moved to a more implicit, structure-driven model. There is no longer a direct UI menu for "return" or "end" actions. Instead, completion is determined by the workflow's graph structure and node configuration—such as break conditions, loop counts, and outputs set in the configuration panels. This means the end of an iteration or loop is inferred automatically based on how you connect and configure nodes, not by a manual menu action. This change was made to improve consistency and robustness in workflow execution, but it does mean the UI and documentation may be out of sync right now [[source](https://github.com/langgenius/dify/pull/21052)]. For configuring iteration and loop nodes: you can set up parallel execution, error handling modes (terminate, continue on error, or remove abnormal output), loop variables, break conditions, and loop counts directly in the node panels. The backend now manages the orchestration, and the frontend focuses on configuration and visualization [[iteration node code](https://github.com/langgenius/dify/blob/1d41b642ca84f9ab3bc39db55a6fbc853a62bb87/api/core/workflow/nodes/iteration/iteration_node.py)] [[loop node code](https://github.com/langgenius/dify/blob/1d41b642ca84f9ab3bc39db55a6fbc853a62bb87/api/core/workflow/nodes/loop/loop_node.py)]. If you want to contribute, updating the documentation or UI hints to reflect this new implicit model would be very helpful for other users. Let me know if you want more technical details or examples for a specific workflow scenario! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/3b9bfebd-9332-45f1-8260-e79b5a4f56ea?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3b9bfebd-9332-45f1-8260-e79b5a4f56ea?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3b9bfebd-9332-45f1-8260-e79b5a4f56ea?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3b9bfebd-9332-45f1-8260-e79b5a4f56ea?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3b9bfebd-9332-45f1-8260-e79b5a4f56ea?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3b9bfebd-9332-45f1-8260-e79b5a4f56ea?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3b9bfebd-9332-45f1-8260-e79b5a4f56ea?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/21225)
Author
Owner

@chenxs-sx commented on GitHub (Jun 19, 2025):

I have tried many methods, but I cannot output the result of the loop to the next step for parameter extraction. Can you provide more specific instructions?

Image

Thank you very much
@dosu

@chenxs-sx commented on GitHub (Jun 19, 2025): I have tried many methods, but I cannot output the result of the loop to the next step for parameter extraction. Can you provide more specific instructions? <img width="1820" alt="Image" src="https://github.com/user-attachments/assets/651bf1ce-0c08-4bdc-963f-835305703297" /> Thank you very much @dosu
Author
Owner

@dosubot[bot] commented on GitHub (Jun 19, 2025):

To pass the result of a loop to the next step for parameter extraction in Dify, you need to make sure the outputs from your LoopNode are correctly referenced by the downstream node (like ParameterExtractorNode) using variable selectors.

Here’s how it works:

  1. The LoopNode stores its outputs in a variable pool, using keys based on the node ID and the output variable name (for example, ['<loop_node_id>', '<output_key>']). The outputs include your loop variables and the loop round count. You can configure which variables to output in the LoopNode’s settings panel. LoopNode implementation

  2. In your ParameterExtractorNode (or any node that needs the loop result), set the variable selector (often called query or similar in the config) to match the output key from the LoopNode. For example, if your LoopNode’s ID is loop_1 and your output variable is result, use ['loop_1', 'result'] as the selector. ParameterExtractorNode implementation

  3. The workflow engine will pass the value from the variable pool to the next node, allowing you to extract or process it as needed. GraphEngine variable pool logic

If you’re not seeing the expected output, double-check:

  • The output variable name in the LoopNode matches what you reference in the next node.
  • The variable selector path is correct (case-sensitive and matches the node/output structure).
  • The LoopNode is actually producing the output you expect (check its config and outputs).

If you share your node IDs and output variable names, I can help you write the exact selector. Let me know if you need a concrete example or run into a specific error!

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jun 19, 2025): <!-- Answer --> To pass the result of a loop to the next step for parameter extraction in Dify, you need to make sure the outputs from your LoopNode are correctly referenced by the downstream node (like ParameterExtractorNode) using variable selectors. Here’s how it works: 1. The LoopNode stores its outputs in a variable pool, using keys based on the node ID and the output variable name (for example, `['<loop_node_id>', '<output_key>']`). The outputs include your loop variables and the loop round count. You can configure which variables to output in the LoopNode’s settings panel. [LoopNode implementation](https://github.com/langgenius/dify/blob/1d41b642ca84f9ab3bc39db55a6fbc853a62bb87/api/core/workflow/nodes/loop/loop_node.py) 2. In your ParameterExtractorNode (or any node that needs the loop result), set the variable selector (often called `query` or similar in the config) to match the output key from the LoopNode. For example, if your LoopNode’s ID is `loop_1` and your output variable is `result`, use `['loop_1', 'result']` as the selector. [ParameterExtractorNode implementation](https://github.com/langgenius/dify/blob/1d41b642ca84f9ab3bc39db55a6fbc853a62bb87/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py) 3. The workflow engine will pass the value from the variable pool to the next node, allowing you to extract or process it as needed. [GraphEngine variable pool logic](https://github.com/langgenius/dify/blob/1d41b642ca84f9ab3bc39db55a6fbc853a62bb87/api/core/workflow/graph_engine/graph_engine.py) If you’re not seeing the expected output, double-check: - The output variable name in the LoopNode matches what you reference in the next node. - The variable selector path is correct (case-sensitive and matches the node/output structure). - The LoopNode is actually producing the output you expect (check its config and outputs). If you share your node IDs and output variable names, I can help you write the exact selector. Let me know if you need a concrete example or run into a specific error! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/3b182325-9569-45a1-aeed-fa60639add0b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3b182325-9569-45a1-aeed-fa60639add0b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3b182325-9569-45a1-aeed-fa60639add0b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3b182325-9569-45a1-aeed-fa60639add0b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3b182325-9569-45a1-aeed-fa60639add0b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3b182325-9569-45a1-aeed-fa60639add0b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3b182325-9569-45a1-aeed-fa60639add0b?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/21225)
Author
Owner

@chenxs-sx commented on GitHub (Jun 19, 2025):

Can I trouble you to provide an example?
I am currently executing a query in a loop until a task execution result is obtained (a query operation is time-consuming), and then the next step obtains the result after the loop.
The input variable parameter of the loop is requestid->string, and the output variable is result -> Array[Object]

It happens that this example can be used for document updates, hehe.

Thank you very much, @dosu

Image
@chenxs-sx commented on GitHub (Jun 19, 2025): Can I trouble you to provide an example? I am currently executing a query in a loop until a task execution result is obtained (a query operation is time-consuming), and then the next step obtains the result after the loop. The input variable parameter of the loop is requestid->string, and the output variable is result -> Array[Object] It happens that this example can be used for document updates, hehe. Thank you very much, @dosu <img width="1657" alt="Image" src="https://github.com/user-attachments/assets/e2ffb1f7-c30e-494e-bb7c-421ab73a6323" />
Author
Owner

@dosubot[bot] commented on GitHub (Jun 19, 2025):

Here’s a concrete example for your scenario, based on the current Dify workflow engine:

  1. LoopNode configuration:

    • Set the input variable as requestid (type: string).
    • Set the output variable as result (type: array[object]).
    • Configure the loop to run up to your desired max count (e.g., 20).
    • Add a break condition: for example, exit if result is not empty. This is done by adding a condition in the loop node config referencing the output variable (e.g., ['<loop_node_id>', 'result'] is not empty).
  2. Inside the loop: Place your query node(s) that use requestid as input and produce a result array of objects as output.

  3. After the loop: To extract the result, use a ParameterExtractorNode (or any node that needs the loop output). In its config, set the variable selector (query) to ['<loop_node_id>', 'result']. This will pull the final array of objects produced by the loop. For example, if your LoopNode’s ID is loop_1, use ['loop_1', 'result'] as the selector.

  4. Passing data: The workflow engine manages the variable pool, so as long as your selectors match the node IDs and variable names, the data will flow correctly to the next step [LoopNode implementation] [ParameterExtractorNode implementation].

Example variable selector for the next node:
If your LoopNode is loop_1 and your output is result, set the next node’s input/query to ['loop_1', 'result'].

Common pitfalls:

  • Make sure the output variable name in the LoopNode matches exactly what you reference downstream (case-sensitive).
  • The break condition should reference the correct variable path.
  • If the result is empty, check your loop logic and break condition.

Let me know if you want a JSON config snippet or have a specific node ID/variable name you want to use!

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jun 19, 2025): <!-- Answer --> Here’s a concrete example for your scenario, based on the current Dify workflow engine: 1. **LoopNode configuration**: - Set the input variable as `requestid` (type: string). - Set the output variable as `result` (type: array[object]). - Configure the loop to run up to your desired max count (e.g., 20). - Add a break condition: for example, exit if `result` is not empty. This is done by adding a condition in the loop node config referencing the output variable (e.g., `['<loop_node_id>', 'result']` is not empty). 2. **Inside the loop**: Place your query node(s) that use `requestid` as input and produce a `result` array of objects as output. 3. **After the loop**: To extract the result, use a ParameterExtractorNode (or any node that needs the loop output). In its config, set the variable selector (query) to `['<loop_node_id>', 'result']`. This will pull the final array of objects produced by the loop. For example, if your LoopNode’s ID is `loop_1`, use `['loop_1', 'result']` as the selector. 4. **Passing data**: The workflow engine manages the variable pool, so as long as your selectors match the node IDs and variable names, the data will flow correctly to the next step [[LoopNode implementation](https://github.com/langgenius/dify/blob/1d41b642ca84f9ab3bc39db55a6fbc853a62bb87/api/core/workflow/nodes/loop/loop_node.py)] [[ParameterExtractorNode implementation](https://github.com/langgenius/dify/blob/1d41b642ca84f9ab3bc39db55a6fbc853a62bb87/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py)]. **Example variable selector for the next node:** If your LoopNode is `loop_1` and your output is `result`, set the next node’s input/query to `['loop_1', 'result']`. **Common pitfalls:** - Make sure the output variable name in the LoopNode matches exactly what you reference downstream (case-sensitive). - The break condition should reference the correct variable path. - If the result is empty, check your loop logic and break condition. Let me know if you want a JSON config snippet or have a specific node ID/variable name you want to use! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/fb10131c-c448-4312-94d9-b5db4696f591?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fb10131c-c448-4312-94d9-b5db4696f591?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fb10131c-c448-4312-94d9-b5db4696f591?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fb10131c-c448-4312-94d9-b5db4696f591?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fb10131c-c448-4312-94d9-b5db4696f591?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fb10131c-c448-4312-94d9-b5db4696f591?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fb10131c-c448-4312-94d9-b5db4696f591?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/21225)
Author
Owner

@chenxs-sx commented on GitHub (Jun 19, 2025):

You can see the screenshot I provided. In the loop, there is no setting menu for output variables. I expected it to output result -> Array[Object], but there is no button for output, and the output result cannot be selected in the downstream node.

Image Only variable conditions are output, and no result is output. Thank you very much, @dosu
@chenxs-sx commented on GitHub (Jun 19, 2025): You can see the screenshot I provided. In the loop, there is no setting menu for output variables. I expected it to output result -> Array[Object], but there is no button for output, and the output result cannot be selected in the downstream node. <img width="1611" alt="Image" src="https://github.com/user-attachments/assets/d1ca7d63-e2a1-4eb5-bbc0-43d6171705d4" /> Only variable conditions are output, and no result is output. Thank you very much, @dosu
Author
Owner

@dosubot[bot] commented on GitHub (Jun 19, 2025):

This is a known limitation in the current Dify workflow: the LoopNode only exposes output variables if you explicitly define them as loop variables in the loop node’s configuration panel. There isn’t a separate “output” menu or button—only loop variables you create will be available as outputs to downstream nodes. To output result → Array[Object], you need to add a loop variable named result with type array[object] in the loop node’s config. Then, make sure your loop logic assigns the desired value to this variable. Only then will result be selectable in downstream nodes. There’s no automatic way to pass out intermediate node results unless you do this, which can be confusing since it’s not clearly documented or obvious in the UI yet. If you need step-by-step help on setting up the loop variable, let me know!
LoopNode implementation reference

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jun 19, 2025): <!-- Answer --> This is a known limitation in the current Dify workflow: the LoopNode only exposes output variables if you explicitly define them as loop variables in the loop node’s configuration panel. There isn’t a separate “output” menu or button—only loop variables you create will be available as outputs to downstream nodes. To output result → Array[Object], you need to add a loop variable named result with type array[object] in the loop node’s config. Then, make sure your loop logic assigns the desired value to this variable. Only then will result be selectable in downstream nodes. There’s no automatic way to pass out intermediate node results unless you do this, which can be confusing since it’s not clearly documented or obvious in the UI yet. If you need step-by-step help on setting up the loop variable, let me know! [LoopNode implementation reference](https://github.com/langgenius/dify/blob/1d41b642ca84f9ab3bc39db55a6fbc853a62bb87/web/app/components/workflow/nodes/loop/panel.tsx) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/ca9580e4-4743-41e1-bc84-26fa517c15ca?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/ca9580e4-4743-41e1-bc84-26fa517c15ca?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/ca9580e4-4743-41e1-bc84-26fa517c15ca?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/ca9580e4-4743-41e1-bc84-26fa517c15ca?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/ca9580e4-4743-41e1-bc84-26fa517c15ca?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/ca9580e4-4743-41e1-bc84-26fa517c15ca?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/ca9580e4-4743-41e1-bc84-26fa517c15ca?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/21225)
Author
Owner

@chenxs-sx commented on GitHub (Jun 19, 2025):

I have previously set the loop variable for the loop, and the command for the variable is the same as the variable name output by the code execution in the loop. There is a search variable below the loop variable, and this value can only be selected from the upstream variable parameter. The output result of this loop is the output result of the upstream node of the loop, not the output result of my code execution.

Image

Thank you very much。 @dosu

@chenxs-sx commented on GitHub (Jun 19, 2025): I have previously set the loop variable for the loop, and the command for the variable is the same as the variable name output by the code execution in the loop. There is a search variable below the loop variable, and this value can only be selected from the upstream variable parameter. The output result of this loop is the output result of the upstream node of the loop, not the output result of my code execution. <img width="1653" alt="Image" src="https://github.com/user-attachments/assets/fb542aae-fd79-4998-aa39-372d3682d6e8" /> Thank you very much。 @dosu
Author
Owner

@dosubot[bot] commented on GitHub (Jun 19, 2025):

This is a current limitation in Dify’s workflow engine: even if you set a loop variable with the same name as your code output, the loop variable’s value will only reflect what you explicitly assign to it inside the loop. By default, the loop variable picker only lets you select upstream variables, not dynamic results from code execution within the loop. That’s why your loop output is showing the upstream value, not the code result.

To solve this, add a Variable Assigner Node inside your loop, after your code execution node. Use it to assign the code node’s output (e.g., ['<code_node_id>', 'result']) to your loop variable (e.g., ['<loop_node_id>', 'result']). This bridges the gap and makes the code result available as the loop output for downstream nodes. This is the recommended pattern for dynamic loop outputs in Dify right now reference.

If you want a step-by-step example or JSON config, let me know your node IDs and variable names!

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jun 19, 2025): <!-- Answer --> This is a current limitation in Dify’s workflow engine: even if you set a loop variable with the same name as your code output, the loop variable’s value will only reflect what you explicitly assign to it inside the loop. By default, the loop variable picker only lets you select upstream variables, not dynamic results from code execution within the loop. That’s why your loop output is showing the upstream value, not the code result. To solve this, add a Variable Assigner Node inside your loop, after your code execution node. Use it to assign the code node’s output (e.g., `['<code_node_id>', 'result']`) to your loop variable (e.g., `['<loop_node_id>', 'result']`). This bridges the gap and makes the code result available as the loop output for downstream nodes. This is the recommended pattern for dynamic loop outputs in Dify right now [reference](https://github.com/langgenius/dify/issues/12354). If you want a step-by-step example or JSON config, let me know your node IDs and variable names! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b1264232-84ab-48b8-aad6-e7d62c56725b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b1264232-84ab-48b8-aad6-e7d62c56725b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b1264232-84ab-48b8-aad6-e7d62c56725b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b1264232-84ab-48b8-aad6-e7d62c56725b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b1264232-84ab-48b8-aad6-e7d62c56725b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b1264232-84ab-48b8-aad6-e7d62c56725b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b1264232-84ab-48b8-aad6-e7d62c56725b?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/21225)
Author
Owner

@chenxs-sx commented on GitHub (Jun 19, 2025):

I have previously used variable assignment after the code is executed in the loop, but this variable assignment can only select upstream parameters, or clear the overwrite, etc., and cannot select the result of the code execution in the loop.

@dosu

@chenxs-sx commented on GitHub (Jun 19, 2025): I have previously used variable assignment after the code is executed in the loop, but this variable assignment can only select upstream parameters, or clear the overwrite, etc., and cannot select the result of the code execution in the loop. @dosu
Author
Owner

@dosubot[bot] commented on GitHub (Jun 19, 2025):

This is a current limitation in Dify’s workflow engine: inside a loop, the Variable Assigner node can only select variables that are already defined as loop variables or are available from upstream nodes. It cannot directly select the output of a code execution node from the same loop iteration, because the workflow engine scopes variable visibility to ensure determinism and safety—outputs from sibling nodes in the same iteration are not available for assignment in real time. Only loop variables explicitly declared in the loop configuration are accessible throughout the loop and to downstream nodes, and these must be assigned explicitly within the loop logic, not dynamically from code node outputs at runtime [LoopNode implementation].

As a workaround, you need to ensure that your code node writes its output to a loop variable (e.g., result) by explicitly assigning it within the loop logic, possibly by routing the code node’s output through a Variable Assigner node that targets the loop variable. However, the Variable Assigner node can only reference variables that are already in the variable pool at that point in the workflow, which usually means upstream or pre-declared loop variables [VariableAssignerNode implementation].

If your workflow requires passing dynamic outputs from a code node to a loop variable within the same iteration, you must structure your loop so that the code node’s output is assigned to the loop variable as part of the loop’s explicit variable assignment logic. There is no UI support yet for dynamically selecting sibling node outputs inside a loop body.

Recent updates have improved variable persistence and conversation variable support, but the core limitation around loop variable assignment remains [PR 20699].

If you want to contribute, clarifying this in the documentation or proposing a UI/engine enhancement for dynamic variable assignment inside loops would be valuable.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jun 19, 2025): <!-- Answer --> This is a current limitation in Dify’s workflow engine: inside a loop, the Variable Assigner node can only select variables that are already defined as loop variables or are available from upstream nodes. It cannot directly select the output of a code execution node from the same loop iteration, because the workflow engine scopes variable visibility to ensure determinism and safety—outputs from sibling nodes in the same iteration are not available for assignment in real time. Only loop variables explicitly declared in the loop configuration are accessible throughout the loop and to downstream nodes, and these must be assigned explicitly within the loop logic, not dynamically from code node outputs at runtime [[LoopNode implementation](https://github.com/langgenius/dify/blob/6b1ad634f15459bd8792ee8df7895735ccf0d511/api/core/workflow/nodes/loop/loop_node.py)]. As a workaround, you need to ensure that your code node writes its output to a loop variable (e.g., `result`) by explicitly assigning it within the loop logic, possibly by routing the code node’s output through a Variable Assigner node that targets the loop variable. However, the Variable Assigner node can only reference variables that are already in the variable pool at that point in the workflow, which usually means upstream or pre-declared loop variables [[VariableAssignerNode implementation](https://github.com/langgenius/dify/blob/6b1ad634f15459bd8792ee8df7895735ccf0d511/api/core/workflow/nodes/variable_assigner/v2/node.py)]. If your workflow requires passing dynamic outputs from a code node to a loop variable within the same iteration, you must structure your loop so that the code node’s output is assigned to the loop variable as part of the loop’s explicit variable assignment logic. There is no UI support yet for dynamically selecting sibling node outputs inside a loop body. Recent updates have improved variable persistence and conversation variable support, but the core limitation around loop variable assignment remains [[PR 20699](https://github.com/langgenius/dify/pull/20699)]. If you want to contribute, clarifying this in the documentation or proposing a UI/engine enhancement for dynamic variable assignment inside loops would be valuable. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/515638e6-1d41-4491-94c7-dfd85a868d37?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/515638e6-1d41-4491-94c7-dfd85a868d37?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/515638e6-1d41-4491-94c7-dfd85a868d37?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/515638e6-1d41-4491-94c7-dfd85a868d37?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/515638e6-1d41-4491-94c7-dfd85a868d37?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/515638e6-1d41-4491-94c7-dfd85a868d37?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/515638e6-1d41-4491-94c7-dfd85a868d37?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/21225)
Author
Owner

@chenxs-sx commented on GitHub (Jul 2, 2025):

The 1.5.0 version of dify encountered a problem again. Using the variable assignment tool, the code execution result could not be obtained.
Code execution: Output results: ids (list), message (for subsequent loop variable assignment)
The loop situation is as follows:

  1. The code execution result outputs 2 parameters, namely result and error
  2. The judgment condition for the end of the loop is: error = 'no'
  3. After the code is executed in the loop, there is a variable assignment tool to assign result to message
    After the loop ends, the result after the variable assignment is output
    Execution action:
    Originally, after the variable assignment, there was a node to end the loop. The loop end condition set at that time was that message was not empty, but the loop failed to take effect and ended after only one execution without starting the loop;
    Therefore, I deleted the end loop node after the variable assignment, and set the error parameter separately in the loop code execution to determine whether to end the loop. When this solution was adopted, the variable assignment node was suspected to fail to execute.

@dosu

@chenxs-sx commented on GitHub (Jul 2, 2025): The 1.5.0 version of dify encountered a problem again. Using the variable assignment tool, the code execution result could not be obtained. Code execution: Output results: ids (list), message (for subsequent loop variable assignment) The loop situation is as follows: 1. The code execution result outputs 2 parameters, namely result and error 2. The judgment condition for the end of the loop is: error = 'no' 3. After the code is executed in the loop, there is a variable assignment tool to assign result to message After the loop ends, the result after the variable assignment is output Execution action: Originally, after the variable assignment, there was a node to end the loop. The loop end condition set at that time was that message was not empty, but the loop failed to take effect and ended after only one execution without starting the loop; Therefore, I deleted the end loop node after the variable assignment, and set the error parameter separately in the loop code execution to determine whether to end the loop. When this solution was adopted, the variable assignment node was suspected to fail to execute. @dosu
Author
Owner

@dosubot[bot] commented on GitHub (Jul 2, 2025):

This is a known limitation in Dify 1.5.0: inside a loop, the Variable Assigner node can only access variables that are already in the variable pool at that point—typically upstream variables or explicitly declared loop variables. It cannot directly reference the output of a code execution node from the same loop iteration, because sibling node outputs are not available for assignment in real time. As a result, even if you try to assign the code node’s output to a loop variable using the Variable Assigner, it won’t work unless the output is already in the pool under the expected selector at that moment in the workflow. This is why your assignment appears to fail and why the loop end condition may not behave as expected see code details.

The current best practice is to ensure your code node writes its output directly to a loop variable (by explicit assignment in the loop logic), and to structure your workflow so that the assignment happens after the code node executes, referencing the correct variable selector. There’s no built-in workaround for dynamic assignment from sibling nodes within the same loop iteration see implementation.

If you want to contribute, clarifying this in the docs or proposing an engine/UI enhancement for dynamic variable assignment inside loops would be valuable. Let me know if you want a concrete example or have a specific workflow structure you want to debug!

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jul 2, 2025): <!-- Answer --> This is a known limitation in Dify 1.5.0: inside a loop, the Variable Assigner node can only access variables that are already in the variable pool at that point—typically upstream variables or explicitly declared loop variables. It cannot directly reference the output of a code execution node from the same loop iteration, because sibling node outputs are not available for assignment in real time. As a result, even if you try to assign the code node’s output to a loop variable using the Variable Assigner, it won’t work unless the output is already in the pool under the expected selector at that moment in the workflow. This is why your assignment appears to fail and why the loop end condition may not behave as expected [see code details](https://github.com/langgenius/dify/blob/cc89d7b1a524ce9ee2f4e87c1665806aefaaa83f/api/core/workflow/nodes/loop/loop_node.py). The current best practice is to ensure your code node writes its output directly to a loop variable (by explicit assignment in the loop logic), and to structure your workflow so that the assignment happens after the code node executes, referencing the correct variable selector. There’s no built-in workaround for dynamic assignment from sibling nodes within the same loop iteration [see implementation](https://github.com/langgenius/dify/blob/cc89d7b1a524ce9ee2f4e87c1665806aefaaa83f/api/core/workflow/nodes/variable_assigner/v2/node.py). If you want to contribute, clarifying this in the docs or proposing an engine/UI enhancement for dynamic variable assignment inside loops would be valuable. Let me know if you want a concrete example or have a specific workflow structure you want to debug! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/a8a921c8-dad0-41f5-9470-399bdb8506e9?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/a8a921c8-dad0-41f5-9470-399bdb8506e9?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/a8a921c8-dad0-41f5-9470-399bdb8506e9?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/a8a921c8-dad0-41f5-9470-399bdb8506e9?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/a8a921c8-dad0-41f5-9470-399bdb8506e9?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/a8a921c8-dad0-41f5-9470-399bdb8506e9?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/a8a921c8-dad0-41f5-9470-399bdb8506e9?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/21225)
Author
Owner

@chenxs-sx commented on GitHub (Jul 2, 2025):

The code in the loop executes the result. I explicitly output the result and use the variable assigner to assign the value to the loop variable. This process does not take effect.

@dosu

@chenxs-sx commented on GitHub (Jul 2, 2025): The code in the loop executes the result. I explicitly output the result and use the variable assigner to assign the value to the loop variable. This process does not take effect. @dosu
Author
Owner

@chenxs-sx commented on GitHub (Jul 2, 2025):

Please see my screenshot:

Image Image Image Image

@dosu

@chenxs-sx commented on GitHub (Jul 2, 2025): Please see my screenshot: <img width="1336" alt="Image" src="https://github.com/user-attachments/assets/fd78a15c-16a3-49a9-96d1-0934e48da9c5" /> <img width="1336" alt="Image" src="https://github.com/user-attachments/assets/30701964-7f5a-4ee1-823b-2acdb31a07fd" /> <img width="735" alt="Image" src="https://github.com/user-attachments/assets/171395cf-5704-49a4-80af-972bcf6cd8fb" /> <img width="666" alt="Image" src="https://github.com/user-attachments/assets/8074a928-43fc-4da4-b3b1-46dab1095d87" /> @dosu
Author
Owner

@dosubot[bot] commented on GitHub (Jul 2, 2025):

Your workflow is running into a core limitation of Dify 1.5.0: inside a loop, the Variable Assigner node cannot directly access the output of a code execution node from the same loop iteration. The variable picker in the Variable Assigner only shows upstream or pre-declared loop variables, not sibling node outputs. This means that even if you explicitly output a value from your code node and try to assign it to a loop variable, the assignment will not take effect unless the variable is already present in the variable pool at that point in the workflow. This is by design in the current engine and is confirmed by the codebase and recent updates (LoopNode implementation, VariableAssignerNode implementation).

There is no workaround to dynamically assign the output of a code node to a loop variable within the same iteration using the Variable Assigner. The only variables reliably available for assignment are those declared as loop variables or passed from upstream. The best you can do is ensure your code node writes directly to a loop variable if possible, or restructure your workflow so that the needed value is available as an input to the loop, not as a sibling output.

If you want to see this improved, a feature request or documentation update would help clarify this for other users. Let me know if you want a step-by-step example of the current best practice or have a specific workflow structure you want to debug.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jul 2, 2025): <!-- Answer --> Your workflow is running into a core limitation of Dify 1.5.0: inside a loop, the Variable Assigner node cannot directly access the output of a code execution node from the same loop iteration. The variable picker in the Variable Assigner only shows upstream or pre-declared loop variables, not sibling node outputs. This means that even if you explicitly output a value from your code node and try to assign it to a loop variable, the assignment will not take effect unless the variable is already present in the variable pool at that point in the workflow. This is by design in the current engine and is confirmed by the codebase and recent updates ([LoopNode implementation](https://github.com/langgenius/dify/blob/68f41bbaa804a03abc046d0df484c1edc50f8066/api/core/workflow/nodes/loop/loop_node.py), [VariableAssignerNode implementation](https://github.com/langgenius/dify/blob/68f41bbaa804a03abc046d0df484c1edc50f8066/api/core/workflow/nodes/variable_assigner/v2/node.py)). There is no workaround to dynamically assign the output of a code node to a loop variable within the same iteration using the Variable Assigner. The only variables reliably available for assignment are those declared as loop variables or passed from upstream. The best you can do is ensure your code node writes directly to a loop variable if possible, or restructure your workflow so that the needed value is available as an input to the loop, not as a sibling output. If you want to see this improved, a feature request or documentation update would help clarify this for other users. Let me know if you want a step-by-step example of the current best practice or have a specific workflow structure you want to debug. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/f6e4c3d7-30ec-421f-8366-86d46c92fb1e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/f6e4c3d7-30ec-421f-8366-86d46c92fb1e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/f6e4c3d7-30ec-421f-8366-86d46c92fb1e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/f6e4c3d7-30ec-421f-8366-86d46c92fb1e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/f6e4c3d7-30ec-421f-8366-86d46c92fb1e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/f6e4c3d7-30ec-421f-8366-86d46c92fb1e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/f6e4c3d7-30ec-421f-8366-86d46c92fb1e?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/21225)
Author
Owner

@chenxs-sx commented on GitHub (Jul 2, 2025):

But my requirement is just to be able to loop through a code and output its results.

@dosu

@chenxs-sx commented on GitHub (Jul 2, 2025): But my requirement is just to be able to loop through a code and output its results. @dosu
Author
Owner

@dosubot[bot] commented on GitHub (Jul 2, 2025):

This is a core limitation in Dify 1.5.0: you cannot directly output the result of a code node from inside a loop to downstream nodes using the Variable Assigner, because the workflow engine only allows assignment from variables already in the variable pool at that point—typically upstream or explicitly declared loop variables, not outputs from sibling nodes in the same loop iteration. Even if you explicitly output a value from your code node and try to assign it to a loop variable, the assignment will not take effect unless the variable is already present in the pool at that moment. There is currently no built-in workaround for this; the only variables reliably available for assignment are those declared as loop variables or passed from upstream nodes. This is confirmed by recent code and PRs, and the limitation remains in place despite recent improvements to variable persistence and debugging features (source).

If your requirement is to loop through a code node and output its results, the only current options are to (1) ensure your code node writes directly to a loop variable if possible, or (2) restructure your workflow so the needed value is available as an input to the loop, not as a sibling output. If you want to see this improved, contributing a feature request or documentation update would help clarify this for others. If you want help designing an alternative workflow, let me know your exact node structure and I can suggest a possible approach.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Jul 2, 2025): <!-- Answer --> This is a core limitation in Dify 1.5.0: you cannot directly output the result of a code node from inside a loop to downstream nodes using the Variable Assigner, because the workflow engine only allows assignment from variables already in the variable pool at that point—typically upstream or explicitly declared loop variables, not outputs from sibling nodes in the same loop iteration. Even if you explicitly output a value from your code node and try to assign it to a loop variable, the assignment will not take effect unless the variable is already present in the pool at that moment. There is currently no built-in workaround for this; the only variables reliably available for assignment are those declared as loop variables or passed from upstream nodes. This is confirmed by recent code and PRs, and the limitation remains in place despite recent improvements to variable persistence and debugging features ([source](https://github.com/langgenius/dify/pull/20699)). If your requirement is to loop through a code node and output its results, the only current options are to (1) ensure your code node writes directly to a loop variable if possible, or (2) restructure your workflow so the needed value is available as an input to the loop, not as a sibling output. If you want to see this improved, contributing a feature request or documentation update would help clarify this for others. If you want help designing an alternative workflow, let me know your exact node structure and I can suggest a possible approach. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/166048c2-091a-40e0-9e8f-d796ccd15740?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/166048c2-091a-40e0-9e8f-d796ccd15740?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/166048c2-091a-40e0-9e8f-d796ccd15740?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/166048c2-091a-40e0-9e8f-d796ccd15740?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/166048c2-091a-40e0-9e8f-d796ccd15740?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/166048c2-091a-40e0-9e8f-d796ccd15740?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/166048c2-091a-40e0-9e8f-d796ccd15740?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/21225)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#14727