All guides

Original explainer

Dify Iteration node: how the three error-handling modes change the output array

Choose Terminate, Continue on Error or Remove Failed Results by whether downstream steps depend on position, and handle null in the output.

AI Nav CityWritten / Updated Sources checked

The Iteration node runs the same sub-workflow on every array element, and what the output array looks like when one element fails depends on the error-handling setting. This guide batch-processes 5 synthetic chapters, picks one error-handling mode, and keeps a later Code node from breaking on failure. You need to be able to edit a Dify workflow. It relies on the official Iteration node page and local simulations; Dify was not logged into, and no workflow or model was run.

Action and acceptance sequence

  1. Confirm array and mode

    Check the upstream array, built-in variables and sequential or parallel mode.[1]

  2. Choose error handling

    Pick Terminate, Continue on Error or Remove Failed Results by whether downstream steps rely on position.[1]

  3. Handle the output

    Filter null before converting to text and keep an identifier in each result.[1]

Check each stage separately; the final section states execution scope.

Confirm the array, variables and mode

The Iteration node takes an array from upstream, such as the result of Parameter Extractor, Code, Knowledge Retrieval or HTTP Request, and runs an internal sub-workflow once per element; internal nodes can read the current element as items and a 0-based index as index, and the output is also an array. The official page lists two modes: sequential processes items in order and can stream through Answer nodes, while parallel handles up to 10 items at once and suits independent operations where order does not matter. The original exercise has 5 chapters: intro, setup, usage, faq and summary. The page does not say how parallel output is arranged, so use sequential mode when order must be kept.[1]

How the three modes differ

The official page gives three settings: Terminate stops on any element error and returns the error message; Continue on Error skips the failed element and puts null at its position; Remove Failed Results skips it and returns only successful results. The page example takes [1, 2, 3] and, with the second element failing, the last two give [result-1, null, result-3] and [result-1, result-3]. Applied to the exercise, if usage fails, Continue on Error returns 5 items with null in the 3rd position, while Remove Failed Results leaves 4 items and faq moves from 4th to 3rd.[1]

Choose by whether downstream relies on position

Choose Continue on Error when results must line up with the original array: the failed position is obvious, but downstream steps must handle null. Choose Remove Failed Results when you only want successes and do not care which failed; positions shift, so give every result its own section_id to work out afterwards which one failed, which in the exercise is usage by set difference. If the batch is only meaningful when everything succeeds, for example a missing chapter blocks publication, choose Terminate. This is a recommendation derived from the three behaviors the page describes; the page itself gives none.[1]

Handle null when converting to text

The official page converts the array to text with a Code node using "\n".join(articleSections) or with a Template node. A local Python check shows that join raises TypeError when it meets None, so with Continue on Error the Code node must filter null first and record how many items were skipped; how the Template node treats null is not described on the page and is unverified. The array results for the three modes come from a local simulation of the page rules, which only restates the documentation and is not Dify output, and the page does not define what counts as a failure. Before adopting this, make one element fail on purpose in a disposable workflow and compare the actual output.[1]

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. Dify · Official sources
    View details