Templates / Generate SQL queries from schema only - AI-powered

Generate SQL queries from schema only - AI-powered

Needs changes

by Yulia ✓ · 56,985 views · created 2024-10-29 · Engineering, AI Chatbot

Needs changes. This template uses 1 thing(s) that n8n 3.0 removes: AI Agent v1 (old agent modes). 1 breaking item(s) found. Static check, last run 2026-10-19.

What this workflow does

This AI workflow has 20 nodes and runs manually, when you click “Execute workflow” (plus 1 other trigger). Along the way it connects OpenAI Chat Model and MySQL.

How it runs

Trigger: Manually, when you click “Execute workflow” (plus 1 other trigger).

  1. List all tables in a database (MySQL): run a query
  2. Load the schema from the local file (Read/Write Files from Disk): reads a file from disk
  3. Extract database schema (MySQL): run a query
  4. Extract data from file (Extract from File): extracts data from a file (from json)
  5. Add table name to output (Edit Fields (Set)): sets 1 field: table
  6. Combine schema data and chat input (Edit Fields (Set)): sets 4 fields: sessionId, action, chatinput…
  7. Convert data to binary (Convert to File): converts data to a file (to json)
  8. AI Agent: runs an AI agent, with model: OpenAI Chat Model; memory: Window Buffer Memory
  9. Save file locally (Read/Write Files from Disk): writes a file to disk
  10. Extract SQL query (Edit Fields (Set)): sets 1 field: query

…plus 5 more steps. See the full node list below.

Services it uses

OpenAI Chat ModelMySQL

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 AI Agent (v1.6): 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.0Replace with
AI Agent v1 (old agent modes)
AI Agent (v1.6)
Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent.

Nodes used (13)

From the author

This workflow is a modification of the previous template on how to create an SQL agent with LangChain and SQLite. The key difference – the agent has access only to the database schema, not to the actual data. To achieve this, SQL queries are made outside the…

Excerpt from Yulia's description on n8n.io.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.