Hey everyone, hoping someone can shed some light on this because I’m completely stumped.
I have two workflows that are supposed to be identical. One works perfectly, the other doesn’t. The only difference is how they were created.
Setup:
- n8n self-hosted (latest, Docker on VPS)
- AI Agent with Google Gemini (gemini-2.5-flash)
- Postgres Tool (postgresTool v2.6, operation: Select) as a tool
- Simple chat interface
The working workflow was built manually in the n8n UI. When I ask “what are the critical CVEs?”, the ReAct loop works as expected: Gemini → Postgres Tool → Gemini and the agent correctly reads and uses the data from the db.
The broken workflow was created programatically via the n8n API. It has the exact same nodes, same credentials, same system prompt, same Postgres config. But the execution order is always: Gemini → Gemini → Postgres Tool — Gemini fires twice before the tool is ever called, so by the time the DB returns data, there’s no second Gemini call left to actually read it. The agent then responds with “no results found” even though the Postgres node clearly shows the correct data in the output panel.
What I’ve tried and ruled out: - System prompt — tried everything from detailed instructions to “ABSOLUTE RULE: call the tool first” to a minimal one-liner. Makes no difference.
- Model — tested Gemini 2.5-flash, 2.5-flash-lite, OpenAI GPT-4. Same broken behaviour on the API-created workflow.
- $fromAI() — tool does get called but returns an empty string “” to the LLM, not sure why
- returnAll: true — data shows in the n8n output panel but LLM still receives “”
- schema mode “list” vs “name” in the Postgres node — no change
promptType: define with explicit {{ $(‘When chat message received’).item.json.chatInput }} — no effect
I’ve compared the JSON of both workflows and they look identical to me. Same node types, same typeVersions, same parameters, same connections. Yet one works and the other doesn’t.
My suspicion is that there’s some internal metadata or cached value that gets set when you build a workflow through the UI but is missing when created via API. Something like cachedResultName or some other field that’s not obvious in the JSON.
Has anyone ran into this? Is there something the n8n UI sets behind the scenes that the API doesn’t? Would really appreciate any pointers, been stuck on this for a while now.
Thanks!
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.)
Share the output returned by the last node
Information on your n8n setup
-
n8n version: latest
-
Database (default: SQLite): postgre SQL
-
n8n EXECUTIONS_PROCESS setting (default: own, main):
-
Running n8n via (Docker, npm, n8n cloud, desktop app): docker on hostinger
-
Operating system: MAC OS
Left : working workflow created through GUI/
Right : exact same workflow created through API/Claude Code (not working)
