Describe the problem/error/question
I’m working on an n8n workflow where an AI Agent node references an “error” variable from a Control node. However, since the Control node hasn’t executed yet during the first run, the AI Agent node throws the error:
“Reference node isn’t executed yet”
I need a way to ensure that the AI Agent node can either:
-
Retrieve the “error” variable if the Control node has executed , OR
-
Use a default value if the Control node hasn’t run yet
What is the error message (if any)?
Reference node isn’t executed yet
Please share your workflow
(Select the nodes on your canvas and use CMD+C/CTRL+C and CMD+V/CTRL+V to copy & paste your workflow here.)
Share the output returned by the last node
<!-- If you need help with data transformations, please also share your expected output. -->
Since the Control node hasn’t executed, the AI Agent node fails when trying to reference its output.
What I’ve tried so far
- Using an expression with optional chaining and nullish coalescing , like:
{{ $("Control").first().json?.error ?? "Control node has not executed yet" }}
➝ Still getting the “Reference node isn’t executed yet” error
- Adding a Set node in the “If False” branch to provide a fallback value.
➝ But the AI Agent node still fails when Control node hasn’t run yet.
- Using a No Operation node to ensure that a value always exists.
➝ This might work, but I’m looking for best practices.
What’s the best approach to handle this in n8n?
Is there a built-in way to prevent referencing unexecuted nodes, or should I always implement a fallback structure manually?