Generate SQL queries from schema only - AI-powered
Configured with Agent, Chat Trigger, Convert To File, Extract From File, and additional nodes. Review the connections and setup before adapting this template.
Node categories in this workflow
- AI & models
- Data store
- Routing
- Transform
- Files / media
- Trigger
Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.
Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.
How it works
The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.
| Node | Category | Type | Operation |
|---|---|---|---|
| OpenAI Chat Model | AI & models | OpenAI Chat Model | See node parameters |
| Window Buffer Memory | Data store | Memory Buffer Window | See node parameters |
| No Operation, do nothing | Routing | No Op | See node parameters |
| List all tables in a database | Data store | My Sql | executeQuery |
| Extract database schema | Data store | My Sql | executeQuery |
| Add table name to output | Transform | Edit Fields | See node parameters |
| Convert data to binary | Transform | Convert To File | toJson |
| Save file locally | Files / media | Read Write File | write |
| Extract data from file | Transform | Extract From File | fromJson |
| Chat Trigger | Trigger | Chat Trigger | See node parameters |
| AI Agent | AI & models | Agent | See node parameters |
| When clicking "Test workflow" | Trigger | Manual Trigger | See node parameters |
| Combine schema data and chat input | Transform | Edit Fields | See node parameters |
| Load the schema from the local file | Files / media | Read Write File | See node parameters |
| Extract SQL query | Transform | Edit Fields | See node parameters |
| Check if query exists | Routing | If | See node parameters |
| Format query results | Transform | Edit Fields | See node parameters |
| Run SQL query | Data store | My Sql | executeQuery |
| Prepare final output | Transform | Edit Fields | See node parameters |
| Combine query result and chat answer | Transform | Merge | See node parameters |
Setup
- Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
- Connect your own credentials through n8n’s credential store. Replace
REPLACE_WITH_*values with your resource identifiers. - Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
- Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.
Requirements
An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.
Credential types declared in the source
mySqlopenAiApi
Workflow notes
Run this part only once
Run this part only once
This section:
- loads a list of all tables from the database hosted on db4free
- extracts the database schema for each table and adds the table name
- converts the schema into a binary JSON format
- saves the schema
./chinook_mysql.jsonfile locally
Now you can use chat to "talk" to your data! 🎉
Pre-workflow setup
On every chat message:
On every chat message:
- The workflow gets the data from the local schema file and extracts it as a JSON object. This way, we achieve two important improvements:
- faster processing time as we don't need to fetch the schema for each table from a slow remote database
- the Agent will know database structure without seeing the actual data
- DB schema is then converted into a long string, JSON fields from the Chat Trigger are added before they are entered into the Agent node.
LangChain AI Agent's system prompt is modified.
LangChain AI Agent's system prompt is modified.
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?"
SQL query extraction
SQL query extraction
Check if the agent's response contains an SQL query. If it does, we extract the query using a regular expression.
Sticky Note7
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.
Sticky Note6
- The SQL node accesses the database and executes the query. The results are then formatted for readability.
- Both the chat response and the query result are displayed in the chat window.
Sticky Note8
When the agent responds without an SQL query, you receive an immediate answer with no additional processing.
Generate SQL queries from schema only - AI-powered
Generate SQL queries from schema only - AI-powered
Purpose and structure
This folder contains the Generate SQL queries from schema only - AI-powered workflow. Its executable nodes use agent, chatTrigger, convertToFile, extractFromFile, if, lmChatOpenAi, manualTrigger, memoryBufferWindow, merge, mySql, noOp, readWriteFile, set. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.
Setup
Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.
Entry points
Chat Trigger, When clicking "Test workflow"
Verification
Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.
Attribution
https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Extractfromfile/1590_Extractfromfile_Converttofile_Create_Triggered.json MIT; preserve source notices.