Generate & test SQL code with GPT/OpenRouter AI and PostgreSQL sandbox
Needs changesWhat this workflow does
This AI workflow has 33 nodes and runs when a chat message arrives. Along the way it connects Postgres, OpenRouter Chat Model, OpenAI and MySQL.
How it runs
Trigger: When a chat message arrives.
- localVariables (Edit Fields (Set)): sets 1 field: instruction
- If: checks a condition and branches into true / false
- AgentName (Edit Fields (Set)): sets 1 field: agentName
- OpenRouterAgent (AI Agent): runs an AI agent, with model: OpenRouter Chat Model; memory: Simple Memory
- getAssistantsList (OpenAI): list (assistant)
- isExecutable (If): checks a condition and branches into true / false
- If: checks a condition and branches into true / false
- setOutputByProvider (Edit Fields (Set)): sets 1 field: output
- wordsForUser (Edit Fields (Set)): sets 3 fields: type, message, threadId
- isAssistantExistsCode (Code): runs custom JavaScript code
…plus 20 more steps. See the full node list below.
Services it uses
Before you upgrade to n8n 3.0
1 thing in this workflow is removed in n8n 3.0. Fix it before you upgrade:
- AI Agent v1 (old agent modes) in OpenRouterAgent (v1.7): replace with Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent.
| Removed in 3.0 | Replace with |
|---|---|
| AI Agent v1 (old agent modes) OpenRouterAgent (v1.7) | Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent. |
Nodes used (11)
- Chat Trigger
@n8n/n8n-nodes-langchain.chatTrigger - Code
n8n-nodes-base.code - Simple Memory
@n8n/n8n-nodes-langchain.memoryBufferWindow - If
n8n-nodes-base.if - Postgres
n8n-nodes-base.postgres - Edit Fields (Set)
n8n-nodes-base.set - OpenRouter Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenRouter - OpenAI
@n8n/n8n-nodes-langchain.openAi - AI Agent
@n8n/n8n-nodes-langchain.agent - MySQL
n8n-nodes-base.mySql - Switch
n8n-nodes-base.switch
From the author
This is the core AI agent used for queryverify.com. Don't trust complex AI-generated SQL queries without double-checking them in a safe environment. That's where queryverify comes in. It automatically creates a test environment with the necessary data,…