I’m running into an issue in n8n when wiring multiple inputs into the AI Agent node. I have two schedules (Schedule Trigger and Schedule Trigger1) that each go through a function (f1 and f2) before reaching the AI Agent. In the AI Agent’s Prompt (User Message) field, I’m referencing both: {{ $(‘f1’).item.json.test1 }} {{ $(‘f2’).item.json.test2 }} The problem: If I only trigger Schedule Trigger1 → f2, I get this error: > This makes sense because f1 never ran in that execution, so the AI Agent doesn’t have any data to pull from it. Basically, n8n throws this error any time you reference a node that didn’t execute earlier in the run. Has anyone found a cleaner way to handle “optional” node inputs in n8n AI Agent prompts without getting this error?
Describe the problem/error/question
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
@Hovec This happens because n8n will throw an error any time you reference a node that never actually ran in that execution. Since only one of your schedules fires, the other function node never exists for that run.
Two solid ways to handle this:
1. Fallback in expression: {{ $(‘f1’).item.json.test1 ‘’ }} {{ $(‘f2’).item.json.test2 ‘’ }} Returns an empty string if the node didn’t run, preventing the error.
2. Merge node: Wire both f1 and f2 into a Merge node (Pass Through or Merge by Index), then have the AI Agent read from the Merge’s output. This way, only the active branch’s data comes through cleanly.
Choose option 1 for allowing blanks or option 2 for a cleaner setup with only active branch data.
Glad to hear the Merge node solution worked out for you @Hovec Yeah, sometimes workflow issues can be a real headache, but it’s all part of the learning process.