Skip to content
FlowHubFluxonLab
A
AI Automationfree

Generate SQL queries from schema only - AI-powered

by Yuliaadapted from n8n official workflow galleryUpdated Aug 2026
RequiresAAI AgentMySQLMySQLOpenAI Chat ModelOpenAI Chat ModelSSimple Memory
Share Post Share
OpenAI Chat ModelOpenAI Chat Mod…MBWindow Buffer MemoryWindow Buffer M…NONo Operation, do nothingNo Operation, d…List all tables in a databaseList all tables…Extract database schemaExtract databas…SeAdd table name to outputAdd table name …CTConvert data to binaryConvert data to…RWSave file locallySave file local…EFExtract data from fileExtract data fr…ChChat TriggerAgAI AgentMaWhen clicking "Test workflow"When clicking "…SeCombine schema data and chat inputCombine schema …RWLoad the schema from the local fileLoad the schema…SeExtract SQL queryExtract SQL que…IfCheck if query existsCheck if query …SeFormat query resultsFormat query re…Run SQL querySePrepare final outputPrepare final o…MeCombine query result and chat answerCombine query r…1234567891011121314
1/5
FLOWS
STEPS · 14
Starts from a chat message

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 AI Agent node, and the results are never passed back to the agent. This approach allows the agent to generate SQL queries based on the structure of tables and their relationships, without having to access the actual data. This makes the process more secure and efficient, especially in cases where data confidentiality is crucial. 🚀 Setup To get started with this workflow, you’ll need to set up a free MySQL server and import your database (check Step 1 and 2 in this tutorial). Of course, you can switch MySQL to another SQL database such as PostgreSQL, the principle remains the same. The key is to download the schema once and save it locally to avoid repeated remote connections. Run the top part of the workflow once to download and store the MySQL chinook database schema file on the server. With this approach, we avoid the need to repeatedly connect to a remote db4free database and fetch the schema every time.

Tags

n8nreference-onlyagentlm-chat-open-aimemory-buffer-windowmy-sql
Connects
AAI AgentmysqlMySQLopenaichatmodelOpenAI Chat ModelSSimple Memory
CategoryAI Automation
Triggermanual
Complexityadvanced
Nodes20
AddedOct 29, 2024

Related workflows

See all AI Automation
ACW
free

Run a multimodal WhatsApp AI assistant with OpenAI for text, voice and images

Quick overview This workflow turns WhatsApp into a multimodal assistant that answers text, voice notes, images, and PDF documents using OpenAI, and can generate images with DALL·E on demand, replying back in WhatsApp with either text, audio, or an image. How it works Triggers when a new WhatsApp message is received. Detects whether the incoming message is text, a voice note, an image, a PDF document, or an unsupported type. For text messages, generates an image with OpenAI DALL·E when the message starts with the configured /image command, and sends the generated image back to the sender. For voice notes, fetches the WhatsApp media URL, downloads the audio, transcribes it with OpenAI, and forwards the transcript to the assistant. For images, fetches the WhatsApp media URL, downloads the image, describes it with OpenAI vision using the configured analysis prompt, and forwards the description (plus any caption) to the assistant. For PDF documents, downloads the file from WhatsApp, extracts the PDF text, and forwards the extracted content (plus any caption) to the assistant, while non-PDF files receive an error message. Uses an OpenAI chat model with per-contact short-term memory to ge

by Dr. Firas
Acalculatormcpclienttoolopenaichatmodel
free

Run a personal assistant for calendar, Gmail and utilities with OpenAI and MCP

Quick overview This workflow runs a chat-based OpenAI assistant in n8n that calls three MCP servers for Google Calendar management, Gmail search and draft replies, and utility tools for weather, currency conversion, and calculations. How it works Receives a chat message in n8n to start or continue a conversation. Loads the assistant configuration (model, memory window, and system prompt) and sends the user message to an OpenAI chat model with short-term conversation memory. When the assistant needs calendar actions, it calls an MCP server that searches, creates, updates, or deletes Google Calendar events. When the assistant needs email actions, it calls an MCP server that searches Gmail messages and creates draft replies for user review. When the assistant needs quick utilities, it calls an MCP server that fetches weather from wttr.in, converts currency using frankfurter.app, or runs calculations. Returns the assistant’s response back to the chat, including any results from the MCP tool calls. Setup Add credentials for OpenAI, Google Calendar (OAuth2), and Gmail (OAuth2) in n8n. Activate the workflow, then copy each MCP Server Trigger Production URL for the Calendar, Gmail, and Uti

by Dr. Firas
AopenaichatmodelserpapigooglesearchS
free

AI agent chat

This workflow employs OpenAI's language models and SerpAPI to create a responsive, intelligent conversational agent. It comes equipped with manual chat triggers and memory buffer capabilities to ensure seamless interactions. To use this template, you need to be on n8n version 1.50.0 or later.

by n8n Team