Natural Language to Google Sheets SQL Converter (GPT-4o + n8n)
Chat to Google Sheets → AI generates Sheets query URL → HTTP fetches data → Formatted table output
- Who
- Anyone who wants to build a natural-language query interface for Google Sheets in n8n, with basic familiarity with API keys and OAuth2 setup.
- You get
- Type questions in plain language and get back queried results from Google Sheets via auto-generated SQL-like URLs; supports multi-turn conversation context.
- You need
- n8n · google-sheets
Constraints
Prerequisites: n8n cloud or self-hosted instance; OpenAI account with billing enabled; Google account; target Google Sheet must be shared as "Anyone with the link can view". Required credentials: openAiApi, googleSheetsOAuth2Api. Costs: OpenAI API usage billed per token; Google Sheets API usually free within quota.
What they did
Author rbreen published an n8n workflow template that receives natural-language questions via Chat Trigger, uses GPT-4o to convert them into Google Sheets SQL query URLs, fetches CSV data via HTTP Request, and formats results into a table using GPT-4.1 Mini. The workflow includes AI Agent, Google Sheets tool, structured output parser, and memory buffer window nodes.
How it went
The template claims to enable: natural language to Sheets SQL conversion, automatic column-letter mapping, structured query generation, real-time data access, and multi-turn conversation context. (Source: author report / template description)
Worth knowing
1. The system prompt hardcodes the author's sample sheet URL and GID; you must manually replace them when using a custom sheet, or the workflow will query the sample data. 2. The target sheet must be shared as "Anyone with the link can view" for the HTTP Request to fetch without additional auth. 3. Google Sheets OAuth2 is required for the column-metadata tool, but the HTTP data fetch relies on the public sharing link, not OAuth. 4. This site has not executed the workflow (reproduction=not_tested). Validate connectivity with the sample sheet before switching to production data. 5. Costs: OpenAI API is billed per token consumed; n8n cloud bills per execution, while self-hosted requires your own infrastructure.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- Get Column Info2 node: connect Google Sheets OAuth2 credentials.
- OpenAI Chat Model1 node: connect OpenAI API credentials.
- OpenAI Chat Model2 node: connect OpenAI API credentials.
- Replace __UKH_SECRET_0__ with your real secret/token (path /nodes/0/parameters/options/systemMessage; possible secret).
Configuration to replace
- Source template is n8n public workflow #7451 (~12 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use. 1 literal secret value(s) replaced with __UKH_…__ placeholders.
Template retrieved: 2026-10-24
Steps
Prepare environment and import workflow
1. Ensure you have an n8n instance, an OpenAI account with payment method, and a Google account. 2. Copy the workflow JSON provided by the template. 3. In n8n, go to Workflows → Import from JSON, paste the JSON, and import. 4. Save the workflow with a descriptive name such as "Google Sheets SQL Query Generator".
Configure OpenAI credentials
1. Go to OpenAI Platform, create an API Key, and ensure your account has billing enabled. 2. In the workflow, open the "OpenAI Chat Model1 (GPT-4o)" node, click Create New Credential, select OpenAI API, paste your key, and save. 3. Apply the same credential to the "OpenAI Chat Model2 (GPT-4.1 Mini)" node for result formatting.
Configure Google Sheets OAuth2
1. Go to Google Cloud Console, create or select a project, and enable the Google Sheets API. 2. Navigate to Credentials → Create Credentials → OAuth 2.0 Client IDs, set application type to Web Application. 3. Add the authorized redirect URI required by your n8n credential setup, then copy the Client ID and Client Secret. 4. In n8n, click the "Get Column Info2" node, choose Create New Credential → Google Sheets OAuth2 API, enter the ID and Secret, and complete the OAuth flow.
Prepare sheet and set references
Option A (sample data): Open the author's Sample Marketing Data sheet, make a copy to your Google Drive, and set sharing to "Anyone with the link can view". Option B (custom sheet): Ensure your own sheet has the same link-sharing permission enabled. Then configure nodes: - Get Column Info2: set Document ID to your sheet ID; set Sheet Name to your column metadata sheet (e.g., "Columns") to provide AI with column-letter mappings. - HTTP Request: no manual URL needed; the AI Agent generates it dynamically. Just ensure the sheet sharing permission is correct.
Update AI Agent system prompt (required for custom sheets)
If using your own sheet, update the system message in the "AI Agent3" node: 1. Replace the Google Sheet URL in the prompt with your own sheet address. 2. Update the GID to match your data sheet's gid. 3. Keep the query structure format unchanged. Below is the original system message from the node (source: workflow.json) for reference when replacing:
Execution prompt · Source text。AI Agent3 node systemMessage field; replace URL and GID when using a custom sheet
# MVP System Prompt — Google Sheets Ask-YOUR_OPENAI_KEY_HERE Rule, you must always use the column tool for every question and followup question to know the column names and column letters. write 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. must include google sheets entire url before the query. do not truncate. "https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?gid=365710158#gid=365710158" example: 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 You can only use column letters, no names ouptut data like this. { "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" }Trigger chat and view formatted results
1. After activating the workflow, send a natural-language question via the Chat Trigger (webhook), e.g., "What was the total sales by channel last month?" 2. AI Agent3 calls Get Column Info2 to retrieve column names and letter mappings, then generates a Google Sheets query URL. 3. The HTTP Request node executes that URL to fetch CSV data. 4. Write into Table Output1 uses GPT-4.1 Mini to format the data into a single table with dimensions first, then metrics.
Execution prompt · Source text。Write into Table Output1 node systemMessage field
write this into one table. output as dimensions, then metrics
Prompt you can copy
Setup guidance · Editorial suggestion。Hand to setup assistant; confirm inputs and permissions before proceeding step by step
This block is the prompt. Ads are never placed here.
You are reproducing n8n template 7451: natural language to Google Sheets SQL. First confirm you have an n8n instance, an OpenAI API key, and Google OAuth2 credentials. Then import the workflow, configure credentials, prepare the sheet, and replace the URL and GID in the AI Agent system prompt if using a custom sheet.
When replacing the sample URL and GID in the prompt, keep the /gviz/tq?tqx=out:csv&gid=...&tq=... structure intact.
Source
Natural language to SQL converter for Google Sheets with GPT-4o · rbreen · n8n.io · 2025-08-15
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.