Generate SQL queries from schema only - AI-powered
    100%
    Data Processing
    0(0 reviews)
    5425 downloads

    Generate SQL queries from schema only - AI-powered

    NM

    Curated by n8n Markets team

    Last updated: March 8, 2026

    This workflow is a modification of the previous template on how to [create an SQL agent with LangChain and SQLite](https://n8n.io/workflows/2292-talk-to-your-sqlite-database-with-a-langchain-ai-agent/). *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](https://blog.n8n.io/compare-databases/)). *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. As a result, we reach greater processing speed and efficiency. ### 🗣️ Chat with your data 1. Start a chat: send a message in the chat window. 2. The workflow loads the locally saved MySQL database schema, without having the ability to touch the actual data. The file contains the full structure of your MySQL database for analysis. 3. The Langchain AI Agent receives the schema, your input and begins to work. 4. The AI Agent generates SQL queries and brief comments based solely on the schema and the user’s message. 5. An IF node checks whether the AI Agent has generated a query. When: - Yes: the AI Agent passes the SQL query to the next MySQL node for execution. - No: You get a direct answer from the Agent without further action. 6. The workflow formats the results of the SQL query, ensuring they are convenient to read and easy to understand. 7. Once formatted, you get both the Agent answer and the query result in the chat window. ### 🌟 Example queries Try these sample queries to see the schema-driven AI Agent in action: 1. Would you please list me all customers from Germany? 2. What are the music genres in the database? 3. What tables are available in the database? 4. Please describe the relationships between tables. - In this example, the AI Agent does not need to create the SQL query. And if you prefer to keep the data private, you can manually execute the generated SQL query in your own environment using any database client or tool you trust 🗄️ 💭 The AI Agent memory node does not store the actual data as we run SQL-queries outside the agent. It contains the database schema, user questions and the initial Agent reply. Actual SQL query results are passed to the chat window, but the values are not stored in the Agent memory.

    What's Included

    • Complete n8n workflow template with 0 nodes. Ready to import and customize.

    Requirements

    n8n instance (self-hosted or cloud). credentials.

    How to Use

    1. Download the workflow JSON 2. Import into your n8n instance 3. Configure credentials for 4. Activate and enjoy automation

    How to import this template into n8n

    1. Download the workflow JSON file from this page.
    2. In n8n, open Workflows, create a new workflow and choose Import from File.
    3. Open each node that shows a warning and connect your own credentials.
    4. Run the workflow once manually to check the output before you activate it.
    Included in Pro
    • Importable n8n workflow JSON file
    • Download with Builder Pro or Agency Unlimited
    • Built for n8n v1.0++
    • Setup time: 5-15 min

    Included in Builder Pro — $19/mo, 4,177 premium workflows

    Before you activate

    Templates are reviewed before they are listed. Test with your own credentials and data before running it in production.

    Updated Mar 2026
    v1.0
    SSL
    Secure
    GDPR

    100% Secure Checkout

    Refund requests within 7 days of a new subscription

    Dependencies & Requirements

    HTTP Request
    Integration

    ⚠️ 1 service require credentials. Make sure you have accounts set up before importing.

    Reviews

    0

    No reviews yet

    See all 0 reviews ↓
    —

    0 reviews

    5★
    0
    4★
    0
    3★
    0
    2★
    0
    1★
    0

    No reviews yet.

    Questions & Answers

    0

    Log in to ask a question.

    No questions yet. Be the first to ask!

    People Also Bought