Share This Article
Navigating the world of automation often involves handling unpredictable data flows. One common scenario, especially when working with powerful tools like n8n, is figuring out what happens when a step in your workflow unexpectedly produces no results. Maybe you’re querying a database for new users, fetching recent tweets matching a specific keyword, or checking an API for updated orders – sometimes, there’s simply nothing new to report. Knowing how to handle these “empty outputs” is crucial for building robust, error-tolerant automations that run smoothly without constant manual intervention. This guide will walk you through exactly How to Check for Empty Node Output in n8n, ensuring your workflows can intelligently adapt whether they receive a flood of data or none at all. Efficient workflows often involve managing various connections and endpoints; optimizing even the URLs used in your triggers with tools like Switchy for better tracking can be part of building a truly streamlined process.
Why Checking for Empty Output Matters in n8n
Before diving into the “how,” let’s quickly touch upon the “why.” Understanding the importance of handling empty node outputs sets the stage for building more sophisticated and reliable n8n workflows.
- Preventing Workflow Failures: By default, if a node in n8n (like an HTTP Request, Read Binary File, or Database node) produces no data, the workflow execution might stop right there. This is often undesirable, especially if subsequent steps need to run regardless (e.g., logging the attempt, sending a status update).
- Conditional Logic: Many workflows require different actions based on whether data was found. For instance:
- If new customer data is found, add it to a CRM and send a welcome email.
- If no new data is found, perhaps just log “No new customers found” and end the flow gracefully.
Checking for empty output is the key to enabling this kind of conditional branching using nodes like IF or Switch.
- Resource Efficiency: Processing large datasets consumes resources. If a node returns empty, subsequent nodes designed to manipulate data (like a Spreadsheet File node or a Set node operating on items) don’t need to run, saving computation time and potential API calls.
- User Experience (Chatbots/Interfaces): In interactive workflows like chatbots, receiving *no* response because a data lookup node came back empty creates a poor user experience. You need to detect the empty output and formulate an appropriate message, like “Sorry, I couldn’t find any information matching your request.”
Mastering this check transforms your workflows from brittle sequences into resilient, intelligent processes capable of handling real-world data variability.
The Crucial Prerequisite: “Always Output Data”
Here’s the most critical piece of foundational knowledge: before you can even *check* if a node’s output is empty downstream, you must configure the potentially empty node itself to allow the workflow to continue. If you don’t do this, the workflow will likely halt on an empty output, and your checking mechanism (like an IF node) will never even execute.
The setting you need is typically called “Always Output Data”. Here’s how to find and enable it:
- Select the Node: Click on the node in your workflow that might produce an empty output (e.g., the node fetching data from an API, database, or file).
- Open Node Settings: Look for a “Settings” tab or sometimes an “Error Handling” section within the node’s parameter panel. The exact location can vary slightly depending on the node type and your n8n version.
- Enable the Option: Find the checkbox or toggle labeled “Always Output Data” (or similar wording like “Continue on Fail” which might apply in error scenarios but “Always Output Data” is specific to handling empty lists). Enable this option.
- Save Changes: Make sure to save your workflow.

What does “Always Output Data” actually do? When enabled, if the node genuinely finds zero items, instead of stopping, it passes an empty *structure* downstream. This usually looks like an empty array `[]` in the JSON view. This empty structure is what your subsequent IF, Switch, or Filter node can then inspect to determine that no actual data items were produced.
Enabling “Always Output Data” is the non-negotiable first step. Without it, your downstream checks for emptiness will never get a chance to run if the node truly outputs nothing.
n8n Workflow Logic
Historical Approach: Code-Based Checks (Less Common Now)
In earlier versions of n8n or for more complex scenarios, users often relied on the Function or Function Item nodes, or complex expressions within IF/Switch nodes, to detect empty outputs. While still functional, these methods are generally considered less intuitive and more error-prone than the built-in methods available today.
Common patterns you might encounter in older forum posts or tutorials include:
Using a Function Node
You could insert a Function node after the potentially empty node (which has “Always Output Data” enabled). The code inside might look something like this:
// Assume 'items' is the input data from the previous nodeif (items.length === 0 || (items.length === 1 && Object.keys(items[0].json).length === 0)) { // If the input array is empty OR // If the array has one item, but that item's JSON object is empty // (This handles the structure n8n passes when "Always Output Data" is on) return [{ json: { isEmpty: true } }];} else { // Pass through the original items if not empty return items.map(item => ({ json: { ...item.json, isEmpty: false } }));}
This code checks if the incoming `items` array is truly empty or contains just the placeholder empty item. It then adds a flag (`isEmpty: true/false`) that subsequent nodes (like an IF node) can easily check.
Using Expressions in IF/Switch Nodes
Directly within an IF or Switch node, users might employ JavaScript expressions. Setting the node’s input data mode to “Expression”, you might see conditions like:
{{ items.length === 1 && Object.keys(items[0].json).length === 0 }}
{{ Object.keys($items()[0].json).length === 0 }}
(using newer expression syntax)
These expressions attempt to achieve a similar goal: check if the first item passed (remember, “Always Output Data” ensures *something* is passed, even if it’s just an empty shell) has an empty `json` object.
Limitations of Older Methods:
- Complexity: They require writing and understanding code or complex expressions.
- Fragility: Small changes in n8n’s internal data structure could potentially break these expressions.
- Indirect Check: They often rely on checking the *content* of the first item (`items[0].json`) rather than directly checking if the *number* of items received was zero. This works because “Always Output Data” sends a single empty item, but it feels less direct.
- Configuration Nuances: When using expressions like `{{ … === 0 }}` in an IF/Switch node, you typically needed to set the node’s expected input type to “Boolean” for the comparison to work correctly.
While these methods were necessary innovations at the time, thankfully, n8n has evolved to offer much simpler, built-in solutions.
Related Reading
The Modern & Recommended Way: Built-in Conditions
The n8n team has significantly simplified how to check for empty node output. You can now perform these checks directly within conditional nodes like IF, Switch, or even the Filter node using their standard condition interfaces – no code required!
Remember, these methods *still require* the preceding node to have “Always Output Data” enabled.
Here are the two primary, recommended approaches:
Method A: Check if `$json` “Is Empty”
This method directly inspects the JSON data structure passed from the previous node.
- Add an IF (or Switch/Filter) Node: Place it immediately after the node that might be empty (and has “Always Output Data” enabled).
- Configure the Condition:
- In the first value field (often labeled “Value 1”), use an expression to reference the entire incoming JSON data for the *first item*. This is typically done using
{{ $json }}
or sometimes{{ $item(0).$json }}
depending on context and n8n version (hover over the input section in the node to see the structure). For simplicity, let’s assume{{ $json }}
works for the primary input. - Set the “Operation” dropdown to “Is Empty”.
- Leave the second value field (“Value 2”) empty, as the “Is Empty” operation doesn’t require a comparison value.
- In the first value field (often labeled “Value 1”), use an expression to reference the entire incoming JSON data for the *first item*. This is typically done using
- Interpret the Result:
- If the previous node outputted no items (and “Always Output Data” sent the empty structure `[]`), the `{{ $json }}` resolved for the placeholder item will be effectively empty, and the condition `{{ $json }}` “Is Empty” will evaluate to true. The workflow will proceed down the “true” path of the IF node (or the corresponding output of the Switch node).
- If the previous node outputted one or more items with actual data, the `{{ $json }}` will contain data, the condition will evaluate to false, and the workflow will proceed down the “false” path.

Method B: Check if “Items Count” / “Number” “Is Equal To” 0
This is often the most intuitive and direct method. It explicitly checks how many items were passed from the preceding node.
- Add an IF (or Switch/Filter) Node: Place it after the potentially empty node (with “Always Output Data” enabled).
- Configure the Condition:
- Click the “Add Condition” button.
- Select the “Number” condition type from the dropdown list (it might be under a category like “Meta” or “Execution Info”).
- Within the Number condition options, look for a value representing the count of incoming items. This might be labeled “Items Count,” “Input Items,” “Run Index,” or simply “Number” depending on the specific n8n version and context. A common expression to access this directly is
{{ $items().length }}
or by selecting the relevant meta-parameter from the UI. Let’s assume you can select an “Items Count” or similar parameter directly from the UI. - Set the “Operation” to “Is Equal To” or simply “Equals”.
- In the “Value 2” field, enter the number
0
.
- Interpret the Result:
- If the previous node outputted zero items, the “Items Count” will be 0, the condition `Items Count == 0` will evaluate to true, and the workflow proceeds down the “true” path.
- If the previous node outputted one or more items, the “Items Count” will be greater than 0, the condition will evaluate to false, and the workflow proceeds down the “false” path.

Both Method A and Method B are reliable and officially recommended. Method B (checking item count) is often slightly clearer conceptually, as it directly addresses the question “Did the previous node send zero items?”. Choose the one that feels more logical and easier to understand for you and your team.
Optimizing every part of your automated systems, even down to the links you use for triggers or reporting, contributes to overall efficiency. Services like Switchy can help manage and track these links effectively, ensuring you have visibility into how different parts of your automated infrastructure are performing.
Special Case: Handling Empty Output in Chatbots
When dealing with chatbots (e.g., using n8n’s Chat Trigger node), checking for empty output becomes particularly important for managing the conversation flow and providing a good user experience. If a user asks a question, your workflow might query a knowledge base or API. If that query returns empty, you can’t just let the workflow end silently.
Here’s how the empty check fits into a chatbot context:
- Chat Trigger: Receives the user’s message.
- Data Lookup Node: (e.g., HTTP Request, Database Query) Attempts to find information based on the user’s input. Crucially, this node must have “Always Output Data” enabled.
- IF Node (or Switch): Checks for empty output using Method A or Method B described above.
- True Path (Empty Output): Route the workflow to a node that formulates a specific “not found” message (e.g., using a Set node or directly in the response node).
- False Path (Data Found): Route the workflow to nodes that process the found data and formulate a helpful response based on it.
- Respond to Webhook Node: This node is key for explicit control over the chatbot response. Instead of relying on the *last* node’s output (which might be the IF node itself or some processing node), you use “Respond to Webhook”.
- Ensure your Chat Trigger has “Response Mode” set to “Using Respond to Webhook node”.
- Place a “Respond to Webhook” node on both the “true” and “false” paths originating from your IF node.
- Configure each “Respond to Webhook” node to send the appropriate message back to the chat interface (either the “not found” message or the message containing the retrieved data).
- (Optional) Memory Management: If your chatbot needs to remember context across turns (like conversation history), you might use n8n’s Memory nodes (like Get Memory, Set Memory) to store and retrieve information. You could update the memory differently depending on whether data was found or not.
By using this structure, you ensure the user always receives a relevant response, even when the underlying data source comes up empty, preventing confusion and frustration.
In chatbots, explicitly handling empty results and controlling the final response via the “Respond to Webhook” node is vital for a seamless user interaction.
Chatbot Design Principle
Troubleshooting & Common Pitfalls
Even with the simpler methods, you might encounter issues. Here are a few common problems and how to solve them:
- Problem: Workflow stops at the node *before* the IF check.
- Solution: Double-check that you have enabled “Always Output Data” in the settings of the node that is potentially producing the empty output. This is the most common oversight.
- Problem: IF/Switch node condition always evaluates to false, even when you expect empty data.
- Solution 1 (Method A – $json check): Verify the exact expression needed to access the incoming item’s JSON. In some contexts or older n8n versions, it might be
{{ $item(0).$json }}
instead of just{{ $json }}
. Examine the input data view of the IF node when it receives the empty structure to see what the path should be. - Solution 2 (Method B – Items Count): Ensure you are using the correct parameter or expression for the item count. Check the execution data or meta parameters available in the expression editor. Is it
{{ $items().length }}
, or a specific UI element like “Items Count”? - Solution 3 (Check Node Output): Manually run the workflow up to the node *before* the IF check. Inspect its output when it’s supposed to be empty. Does it output an empty array `[]` as expected when “Always Output Data” is on? If it outputs something else (like an error object, or maybe null), your condition needs to check for that specific structure instead.
- Solution 1 (Method A – $json check): Verify the exact expression needed to access the incoming item’s JSON. In some contexts or older n8n versions, it might be
- Problem: Filter node removes the empty item when you wanted to act on it.
- Solution: Remember the Filter node’s purpose is to *pass through* items that match the condition. If you set up a condition to detect emptiness (e.g., Items Count == 0 evaluates to true), the Filter node will pass that “empty” placeholder item only if the condition is met. If you want different *actions* based on empty/not empty, the IF or Switch nodes are generally more appropriate as they provide distinct output paths.
Debugging often involves carefully inspecting the actual data being passed between nodes during workflow execution. Use the execution log and the input/output data views extensively.
Conclusion: Mastering the Empty Check in n8n
Successfully determining How to Check for Empty Node Output in n8n is a fundamental skill for building resilient and intelligent automations. While older methods involving code existed, the modern, built-in approaches are far more straightforward and robust.
To recap the essential steps:
- Enable “Always Output Data”: On the node that might produce empty results, go to its Settings and enable this option. This is non-negotiable.
- Use an IF or Switch Node: Place one of these nodes immediately after the potentially empty node.
- Choose Your Check Method:
- Method A (Recommended): Configure a condition to check if the incoming item count is zero. Use the “Number” condition type, select the parameter for item count (e.g., “Items Count”, or expression
{{ $items().length }}
), set the operation to “Is Equal To”, and the value to0
. - Method B (Also Recommended): Configure a condition to check if the incoming JSON is empty. Use the expression
{{ $json }}
(or similar) as Value 1, and set the operation to “Is Empty”.
- Method A (Recommended): Configure a condition to check if the incoming item count is zero. Use the “Number” condition type, select the parameter for item count (e.g., “Items Count”, or expression
- Build Your Conditional Paths: Define what happens in the “true” (empty) branch and the “false” (not empty) branch of your IF/Switch node.
- For Chatbots: Use the “Respond to Webhook” node for explicit control over the final message sent back to the user.
By implementing these checks, your n8n workflows will become significantly more reliable, capable of handling variations in data flow gracefully and executing the correct logic based on whether data is present or absent. As you continue to refine your automation processes, consider optimizing all components, including how you manage and track essential links using tools designed for the job. For enhanced link management and analytics, especially for webhooks or API endpoints used in your flows, exploring a service like Switchy could provide additional value.