Overview
The Decision node is designed to evaluate a set of user-defined rules against incoming data and apply a "hit policy" to determine the output. This node is useful in scenarios where you need to make decisions based on multiple conditions, such as routing, scoring, or filtering data within an n8n workflow.
Practical examples:
- Selecting the first item that matches a condition.
- Counting how many items meet a specific criterion.
- Finding the maximum or minimum value among results that satisfy certain conditions.
- Summing up values from items that pass a rule.
Properties
| Name | Type | Meaning |
|---|---|---|
| Rule | String | The name of the rule set being evaluated. Useful for documentation or identification. |
| Hit Policy | Options | Determines how matching rules are processed: - Count: Number of items meeting the condition. - First: The result of the first item that meets the condition. - Max: The maximum result value among matching items. - Min: The minimum result value among matching items. - Sum: The sum of result values for all matching items. |
| Rules | Fixed Collection (multiple) | A list of rule items, each containing: - Condition (Boolean): Whether the rule applies. - Result (String): The value associated with this rule. - Description (String): Additional information about the rule. |
Output
The node outputs an array of objects, each with the following structure:
{
"operation": "<Selected Hit Policy>",
"value": <Result based on hit policy>,
"results": [<Array of rule items used for evaluation>],
"item": { ... } // Original input item's JSON data
}
- operation: The selected hit policy (e.g., "first", "count", "max", "min", "sum").
- value: The computed result according to the hit policy.
- results: The array of rule items that were evaluated.
- item: The original input item's JSON data.
This node does not output binary data.
Dependencies
- No external services or API keys are required.
- No special n8n configurations or environment variables are needed.
Troubleshooting
Common issues:
- Incorrect rule configuration: If the rules are not properly defined (e.g., missing conditions or results), the output may be empty or not as expected.
- Type mismatches: For "max", "min", or "sum" policies, ensure that the "Result" field contains numeric values; otherwise, calculations may fail or produce unexpected results.
- Empty input: If no input data is provided, the node will return an empty array.
Error messages:
- Errors related to missing or invalid parameters will typically reference the property name (e.g., "rules.item") and the index of the problematic item.
- If a non-numeric value is used with "max", "min", or "sum", the result may be
NaNor undefined.
How to resolve:
- Double-check your rule definitions, especially the "Result" fields for numeric operations.
- Ensure that at least one rule has its "Condition" set to true if you expect a result.