AutomationFlowsAI & RAG › Natural Language to Sql Converter for Google Sheets with Gpt-4o

Natural Language to Sql Converter for Google Sheets with Gpt-4o

ByRobert Breen @rbreen on n8n.io

This n8n workflow template creates an intelligent data analysis system that converts natural language questions into Google Sheets SQL queries using OpenAI's GPT-4o model. The system generates proper Google Sheets query URLs and executes them via HTTP requests for efficient data…

Chat trigger trigger★★★☆☆ complexityAI-powered12 nodesAgentGoogle Sheets ToolMemory Buffer WindowOpenAI ChatOutput Parser StructuredChat TriggerHTTP Request
AI & RAG Trigger: Chat trigger Nodes: 12 Complexity: ★★★☆☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #7451 — we link there as the canonical source.

This workflow follows the Agent → Chat Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "5a4c2536-9070-40b4-9db1-24e3b6f440fa",
      "name": "AI Agent3",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        224,
        1872
      ],
      "parameters": {
        "options": {
          "systemMessage": "# MVP System Prompt \u2014 Google Sheets Ask-YOUR_OPENAI_KEY_HERE\n\nRule, you must always use the column tool for every question and followup question to know the column names and column letters. \n\nwrite a sql query to send to google sheets based on the location of the google column on the google sheet. The output should look something like this. \n\nmust include google sheets entire url before the query. do not truncate. \"https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?gid=365710158#gid=365710158\" \n\nexample: \nhttps://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/gviz/tq?tqx=out:csv&gid=365710158&tq=SELECT E, SUM(H), SUM(F) GROUP BY E\n\nYou can only use column letters, no names\nouptut data like this. \n\n{\n\t\"query\": \"https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/gviz/tq?tqx=out:csv&gid=365710158&tq=SELECT E, SUM(H), SUM(F) GROUP BY E\"\n}"
        },
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "766b4958-6e0b-4d99-99ce-8fe98a44b019",
      "name": "Get Column Info2",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        368,
        2160
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 467321788,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit#gid=467321788",
          "cachedResultName": "Columns"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?usp=drivesdk",
          "cachedResultName": "Sample Marketing Data"
        },
        "descriptionType": "manual",
        "toolDescription": "Extracts a sheet\u2019s column metadata so downstream steps (querying, validation, docs) can rely on a clean, typed schema. It returns each column\u2019s name, inferred data type, and human-readable description, plus helpful profiling hints."
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "96e7c115-ecfa-40b1-90ac-96760588a56b",
      "name": "Simple Memory2",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        192,
        2144
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "e3fec4d3-f499-4a6e-ac00-70d2f784762c",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        16,
        2128
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "09aab886-f1fd-447f-aded-70242aa27821",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        1440
      ],
      "parameters": {
        "color": 5,
        "width": 1584,
        "height": 1008,
        "content": "## \ud83d\udcec Need Help or Want to Customize This?\n\ud83d\udce7 [robert@ynteractive.com](mailto:robert@ynteractive.com)  \n\ud83d\udd17 [LinkedIn](https://www.linkedin.com/in/robert-breen-29429625/)"
      },
      "typeVersion": 1
    },
    {
      "id": "94911852-7bba-4178-a4bd-1461bf08d3db",
      "name": "Structured Output Parser1",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        528,
        2160
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"query\": \"sql query for google sheets\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "262e5d0d-c616-4332-a0ab-f1bc9d7225ef",
      "name": "OpenAI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        880,
        1840
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "734f8a72-054b-4d04-bd9b-dc85ba160683",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -160,
        1744
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "be5f8fc5-0d06-4acf-8fa8-efca6310f0ec",
      "name": "Get Data from Google Sheet",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        640,
        1888
      ],
      "parameters": {
        "url": "={{ $json.output.query }}",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "71029e6d-3933-49a0-b31b-1461ef3a176f",
      "name": "Write into Table Output1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        864,
        1616
      ],
      "parameters": {
        "text": "={{ $json.data }}",
        "options": {
          "systemMessage": "write this into one table. output as dimensions, then metrics"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "43d7c1a8-0fc0-4877-ab9c-908c3836239a",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1920,
        1440
      ],
      "parameters": {
        "width": 752,
        "height": 1008,
        "content": "## Step-by-Step Setup Instructions\n\n\n### 1. Set Up OpenAI Connections\n\n#### Get API Key:\n1. Go to [OpenAI Platform](https://platform.openai.com/)\n2. Sign in or create an account\n3. Navigate to **API Keys** section\n4. Click **Create new secret key**\n5. Copy the generated API key\n6. **Important**: Add billing information and credits to your OpenAI account\n\n#### Configure Both OpenAI Nodes:\n1. **OpenAI Chat Model1 (GPT-4o)**:\n   - Click on the node\n   - Click **Create New Credential**\n   - Select **OpenAI API**\n   - Paste your API key\n   - Save the credential\n\n2. **OpenAI Chat Model2 (GPT-4.1 Mini)**:\n   - Apply the same OpenAI API credential\n   - This handles result formatting\n\n### 4. Set Up Google Sheets Connection\n\n#### Create OAuth2 Credentials:\n1. Go to [Google Cloud Console](https://console.cloud.google.com/)\n2. Create a new project or select existing one\n3. Enable the **Google Sheets API**\n4. Go to **Credentials** \u2192 **Create Credentials** \u2192 **OAuth 2.0 Client IDs**\n5. Set application type to **Web Application**\n6. Add authorized redirect URIs (get this from n8n credentials setup)\n7. Copy the **Client ID** and **Client Secret**\n\n#### Configure in n8n:\n1. Click on the **Get Column Info2** node\n2. Click **Create New Credential**\n3. Select **Google Sheets OAuth2 API**\n4. Enter your **Client ID** and **Client Secret**\n5. Complete the OAuth flow by clicking **Connect my account**\n6. Authorize the required permissions\n\n### 5. Prepare Your Google Sheet\n\n#### Option A: Use the Sample Data Sheet\n- Access the pre-configured sheet: [Sample Marketing Data](https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?usp=drivesdk)\n- Make a copy to your Google Drive\n- **Important**: Set sharing to \"Anyone with the link can view\"\n\n### 6. Configure Sheet References\n\n1. **Get Column Info2 Node**:\n   - Set **Document ID** to your Google Sheet ID\n   - Set **Sheet Name** to your columns metadata sheet (e.g., \"Columns\")\n   - This provides the AI with column letter mappings\n\n2. **HTTP Request Node**:\n   - No configuration needed - it uses dynamic URLs from the AI agent\n   - Ensure your sheet has proper sharing permissions\n\n### 7. Update System Prompt (If Using Custom Sheet)\n\nIf using your own Google Sheet, update the system prompt in the **AI Agent3** node:\n1. Replace the URL in the system message with your Google Sheet URL\n2. Update the GID (sheet ID) to match your data sheet\n3. Keep the same query structure format\n"
      },
      "typeVersion": 1
    },
    {
      "id": "0081f73b-ae42-424d-8cd1-9f9e0b30c64f",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1136,
        1440
      ],
      "parameters": {
        "width": 752,
        "height": 1008,
        "content": "\n\n### 5. Prepare Your Google Sheet\n\n#### Option A: Use the Sample Data Sheet\n- Access the pre-configured sheet: [Sample Marketing Data](https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?usp=drivesdk)\n- Make a copy to your Google Drive\n- **Important**: Set sharing to \"Anyone with the link can view\"\n\n### 6. Configure Sheet References\n\n1. **Get Column Info2 Node**:\n   - Set **Document ID** to your Google Sheet ID\n   - Set **Sheet Name** to your columns metadata sheet (e.g., \"Columns\")\n   - This provides the AI with column letter mappings\n\n2. **HTTP Request Node**:\n   - No configuration needed - it uses dynamic URLs from the AI agent\n   - Ensure your sheet has proper sharing permissions\n\n### 7. Update System Prompt (If Using Custom Sheet)\n\nIf using your own Google Sheet, update the system prompt in the **AI Agent3** node:\n1. Replace the URL in the system message with your Google Sheet URL\n2. Update the GID (sheet ID) to match your data sheet\n3. Keep the same query structure format\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "AI Agent3": {
      "main": [
        [
          {
            "node": "Get Data from Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory2": {
      "ai_memory": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Get Column Info2": {
      "ai_tool": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Write into Table Output1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Get Data from Google Sheet": {
      "main": [
        [
          {
            "node": "Write into Table Output1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This n8n workflow template creates an intelligent data analysis system that converts natural language questions into Google Sheets SQL queries using OpenAI's GPT-4o model. The system generates proper Google Sheets query URLs and executes them via HTTP requests for efficient data…

Source: https://n8n.io/workflows/7451/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

ModelRouter. Uses chatTrigger, agent, modelSelector, httpRequest. Chat trigger; 28 nodes.

Chat Trigger, Agent, Model Selector +8
AI & RAG

This workflow automates hospital emergency department triage by intelligently processing patient intake information through multiple AI-powered assessment stages. Designed for emergency departments, u

Chat Trigger, Agent, OpenAI Chat +5
AI & RAG

Are you tired of manually sifting through hundreds of LinkedIn profiles to find the right talent? Say goodbye to inefficient recruiting processes and embrace the power of AI-driven candidate selection

Chat Trigger, Agent, OpenAI Chat +5
AI & RAG

Generate high-quality, SEO-optimized content briefs automatically using AI, real-time keyword research, SERP intelligence, and historical content context. This workflow standardizes user inputs, fetch

Memory Buffer Window, Agent, Output Parser Structured +6
AI & RAG

Streamline the final stage of your content production workflow by automating publishing, formatting, metadata generation, and approval routing. This AI-powered subworkflow pulls optimized drafts from

Google Sheets Tool, Memory Buffer Window, Agent +6