Overview
The "Decision" node evaluates a set of user-defined rules against input data and applies a selected "hit policy" to determine the output. This node is useful for implementing decision tables, conditional logic, or simple rule engines within n8n workflows. Common scenarios include filtering items based on conditions, aggregating results (such as sum or count), or selecting specific items (like the first, minimum, or maximum) that meet certain criteria.
Practical examples:
- Route leads based on scoring rules.
- Calculate the total value of items that pass a filter.
- Select the highest-priority task from a list.
Properties
| Name | Type | Meaning |
|---|---|---|
| Rule | String | The name of the rule set being applied. 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, sortable) | A list of rule items, each with: • Condition (Boolean): Whether the rule applies. • Result (String): Value associated with the rule. • Description (String): Optional description for the rule. |
Output
The node outputs an array of objects, one per input item, with the following structure in the json field:
{
"operation": "<selected hit policy>",
"value": <result of applying the hit policy>,
"results": [ /* array of rule items evaluated */ ],
"item": { /* original input item's json */ }
}
- operation: The hit policy used (e.g., "count", "first", "max", "min", "sum").
- value: The computed result according to the hit policy.
- results: The array of rule items after evaluation.
- item: The original input item's JSON data.
This 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:
- If no rules have their "Condition" set to true, the result may be empty, zero, or undefined depending on the hit policy.
- If "Result" fields are not properly formatted (e.g., non-numeric values for "sum", "min", or "max"), the output may be incorrect or unexpected.
- Using the wrong hit policy for your use case can lead to confusing results (e.g., using "sum" when you expect a single item).
Error messages:
- Errors related to missing or malformed rule definitions may occur if required properties are not set.
- If the "rules.item" collection is empty, the output will reflect no matches.
How to resolve:
- Ensure all rule items are correctly defined with valid "Condition" and "Result" values.
- Double-check the selected "Hit Policy" matches your intended logic.