‘Reference Node Isn’t Executed Yet’ Error - How to Fix?

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:

  1. Retrieve the “error” variable if the Control node has executed , OR

  2. 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

  1. 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

  1. 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.

  1. 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?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

hello @burakbeyler

place an empty node before the AI node and refer to it :slight_smile:

Thank you for your reply, I will try this solution and I will share result with you :slight_smile:

Did it work?