n8n workflow template · 19 nodes · OpenAI
Generate SQL queries from schema only - AI-powered is a free n8n workflow template that starts when a chat message is received and works with OpenAI and MySQL. It has 19 nodes, 4 of them AI nodes (OpenAI Chat Model, Window Buffer Memory, Chat Trigger and AI Agent). The notes inside the workflow say: “Now you can use chat to "talk" to your data!” To run it, you add your own credentials for MySQL and OpenAI API.
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
Now you can use chat to "talk" to your data!
It uses only the database schema to generate SQL queries. The agent creates these queries but does not execute them. Instead, it passes them to subsequent nodes.
Example: "Can you show me the list of all German customers?"
Queries are generated only when necessary; for some requests, a query may not be needed. This is because certain questions can be answered directly without SQL execution.
Example: "Can you list me all tables?"
The AI Agent remembers the schema, questions, and final answers, but not data values, since queries run externally. The agent can't access database content.
Check if the agent's response contains an SQL query. If it does, we extract the query using a regular expression.
When the agent responds without an SQL query, you receive an immediate answer with no additional processing.
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
Connect to a free MySQL server and import your database. Follow Step 1 and 2 in this tutorial for more.
The Chinook data used in this workflow is available on GitHub.
The 19 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:
Configure your own credentials after importing. Create each credential in n8n, then select it in the node.
Do you need somewhere to run it? Read our guide to self-hosted n8n.
We can adapt this workflow to your apps, data and process, then deploy and support it.
Contact Us