Decision icon

Decision

Decision Node

Overview

The Decision node is designed to evaluate a set of user-defined rules against incoming data and apply a selected "hit policy" to determine the output. This node is useful in scenarios where you need to make decisions based on multiple conditions, such as filtering, aggregating, or selecting specific items from your data according to custom logic.

Common use cases:

  • Filtering a list of items based on complex conditions.
  • Calculating aggregates (sum, count, min, max) over items that meet certain criteria.
  • Selecting the first item that matches a condition.
  • Implementing business rules or decision tables within an n8n workflow.

Practical examples:

  • Counting how many orders exceed a certain value.
  • Finding the maximum score among test results that pass a threshold.
  • Returning the first customer who meets a VIP status condition.

Properties

Name Type Meaning
Rule String The name of the rule set being evaluated. Used for identification purposes.
Hit Policy Options Determines how matching rules are processed:
- Count: Number of matches
- First: First match
- Max: Maximum result
- Min: Minimum result
- Sum: Sum of results
Rules Fixed Collection (multiple) A collection of rule items, each with:
- Condition (Boolean): Whether the rule applies.
- Result (String): Value associated with the rule.
- Description (String): Description of the rule.

Output

The node outputs a JSON object for each input item with the following structure:

{
  "operation": "<selected hit policy>",
  "value": <result of applying the hit policy>,
  "results": [
    {
      "condition": <boolean>,
      "result": <string>,
      "description": <string>
    },
    ...
  ],
  "item": { ... } // Original input item's json
}
  • operation: The hit policy used (e.g., "count", "first", "max", "min", "sum").
  • value: The computed result based on the hit policy and matching rules.
  • results: The array of rule items evaluated for this input.
  • item: The original input item's JSON data.

Note: The node does not output binary data.

Dependencies

  • No external services or API keys required.
  • No special n8n configuration or environment variables needed.

Troubleshooting

Common issues:

  • Incorrect rule configuration: If the rules are not set up correctly (e.g., missing conditions or invalid result values), the output may be unexpected or empty.
  • Type mismatches: For policies like "max", "min", or "sum", ensure that the "Result" field contains numeric values; otherwise, calculations may fail or produce incorrect results.
  • Empty input: If no input data is provided, the node will not output any results.

Error messages:

  • Errors related to missing or malformed parameters (such as missing "rules.item") may occur if the node's properties are not properly configured. Double-check all required fields.
  • If a non-numeric value is used with "max", "min", or "sum", the output may be NaN or undefined. Ensure all "Result" fields are numbers when using these policies.

Links and References

Discussion