Generate BigQuery SQL from natural language queries using GPT-4o chat
Give business users a chat box; get back valid BigQuery SQL and live query results.
The workflow:
- Captures a plain-language question from a chat widget or internal portal.
- Fetches the current table + column schema from your BigQuery dataset (via
INFORMATION_SCHEMA). - Feeds both the schema and the question to GPT-4o so it can craft a syntactically correct SQL query using only fields that truly exist.
- Executes the AI-generated SQL in BigQuery and returns the results.
- Stores a short-term memory by session, enabling natural follow-up questions.
Perfect for analysts, customer-success teams, or any stakeholder who needs data without writing SQL.
⚙️ Setup Instructions
-
Import the workflow
- n8n → Workflows → Import from File (or Paste JSON) → Save
-
Add credentials
| Service | Where to create credentials | Node(s) to update | |---------|----------------------------|-------------------| | OpenAI | <https://platform.openai.com> → Create API key | OpenAI Chat Model | | Google BigQuery | Google Cloud Console → IAM & Admin → Service Account JSON key | Google BigQuery (schema + query) | -
Point the schema fetcher to your dataset
- In Google BigQuery1 you’ll see:
SELECT table_name, column_name, data_type FROM `n8nautomation-453001.email_leads_schema.INFORMATION_SCHEMA.COLUMNS` - Replace
n8nautomation-453001.email_leads_schemawithYOUR_PROJECT.YOUR_DATASET. - Keep the rest of the query the same—BigQuery’s
INFORMATION_SCHEMAalways surfacestable_name,column_name, anddata_type.
- In Google BigQuery1 you’ll see:
-
Update the execution node
- Open Google BigQuery (the second BigQuery node).
- In Project ID select your project.
- The SQL Query field is already
{{ $json.output.query }}so it will run whatever the AI returns.
-
(Optional)Embed the chat interface
-
Test end-to-end
- Open the embedded chat widget.
- Ask: “How many distinct email leads were created last week?”
- After a few seconds the workflow will return a table of results—or an error if the schema lacks the requested fields.
- As specific questions about your data
-
Activate
- Toggle Active so the chat assistant is available 24/7.
🧩 Customization Ideas
- Row-limit safeguard: automatically append
LIMIT 1000to every query. - Chart rendering: send query results to Google Sheets + Looker Studio for instant visuals.
- Slack bot: forward both the question and the SQL result to a Slack channel for team visibility.
- Schema caching: store the INFORMATION_SCHEMA result for 24 hours to cut BigQuery costs.
Contact
- Email: rbreen@ynteractive.com
- Website: https://ynteractive.com
- YouTube: https://www.youtube.com/@ynteractivetraining
- LinkedIn: https://www.linkedin.com/in/robertbreen
Generate BigQuery SQL from Natural Language Queries using GPT-4o Chat
This n8n workflow leverages the power of AI to convert natural language questions into executable Google BigQuery SQL queries. It simplifies data querying for users who may not be proficient in SQL, allowing them to interact with their BigQuery data using plain English.
What it does
This workflow automates the following steps:
- Listens for Natural Language Queries: It starts by receiving a natural language question (e.g., "Show me the total sales for the last quarter").
- Maintains Conversation Context: It uses a simple memory buffer to keep track of the conversation history, allowing for more coherent and context-aware SQL generation.
- Generates SQL with AI Agent: An AI Agent, powered by an OpenAI Chat Model (like GPT-4o), processes the natural language query and the conversation history to generate a BigQuery SQL query.
- Structures Output: A structured output parser ensures the generated SQL is correctly formatted and ready for execution.
- Executes BigQuery SQL: It then executes the generated SQL query against your specified Google BigQuery dataset.
- Aggregates Results: The results from BigQuery are aggregated into a single output.
- Prepares Response: A Code node processes the BigQuery results, preparing them for a user-friendly response.
- Merges and Responds: Finally, it merges the original query with the BigQuery results to provide a comprehensive answer back to the user.
Prerequisites/Requirements
To use this workflow, you will need:
- n8n Instance: A running n8n instance.
- OpenAI API Key: An API key for OpenAI (for the Chat Model, e.g., GPT-4o).
- Google BigQuery Account: Access to a Google BigQuery project and dataset.
- Google BigQuery Credentials: Configured Google BigQuery credentials in n8n with appropriate permissions to execute queries.
Setup/Usage
- Import the workflow: Download the provided JSON and import it into your n8n instance.
- Configure Credentials:
- OpenAI Chat Model: Configure your OpenAI API Key credential in the "OpenAI Chat Model" node.
- Google BigQuery: Configure your Google BigQuery credentials in the "Google BigQuery" node. Ensure these credentials have the necessary permissions to read from your BigQuery tables.
- Customize BigQuery Query (Optional): The "Google BigQuery" node is set up to execute a query. You might need to adjust the
project,dataset, andtablenames within the generated SQL or provide schema information to the AI agent for better results. - Activate the workflow: Once configured, activate the workflow.
- Send a chat message: Use the "When chat message received" trigger to send a natural language query to the workflow. The output will contain the generated SQL and the results from BigQuery.
Related Templates
Newsletter signup flow with Email Verification API, Gmail & Google Sheets tracking
Newsletter Sign-up with Email Verification & Welcome Email Automation 📋 Description A complete, production-ready newsletter automation workflow that validates email addresses, sends personalized welcome emails, and maintains comprehensive logs in Google Sheets. Perfect for marketing teams, content creators, and businesses looking to build high-quality email lists with minimal manual effort. ✨ Key Features Email Verification Real-time validation using Verifi Email API Checks email format (RFC compliance) Verifies domain existence and MX records Detects disposable/temporary email addresses Identifies potential spoofed emails Automated Welcome Emails Personalized HTML emails with subscriber's first name Beautiful, mobile-responsive design with gradient headers Branded confirmation and unsubscribe links Sent via Gmail (or SMTP) automatically to valid subscribers Smart Data Handling Comprehensive logging to Google Sheets with three separate tabs Handles incomplete submissions gracefully Preserves original user data throughout verification process Tracks source attribution for multi-channel campaigns Error Management Automatic retry logic on API failures Separate logging for different error types Detailed technical reasons for invalid emails No data loss with direct webhook referencing 🎯 Use Cases Newsletter sign-ups on websites and landing pages Lead generation forms with quality control Marketing campaigns requiring verified email lists Community building with automated onboarding SaaS product launches with email collection Content creator audience building E-commerce customer list management 📊 What Gets Logged Master Log (All Subscribers) Timestamp, name, email, verification result Verification score and email sent status Source tracking, disposable status, domain info Invalid Emails Log Detailed rejection reasons Technical diagnostic information MX record status, RFC compliance Provider information for troubleshooting Invalid Submissions Log Incomplete form data Missing required fields Timestamp for follow-up 🔧 Technical Stack Trigger: Webhook (POST endpoint) Email Verification: Verifi Email API Email Sending: Gmail OAuth2 (or SMTP) Data Storage: Google Sheets (3 tabs) Processing: JavaScript code nodes for data formatting 🚀 Setup Requirements Google Account - For Sheets and Gmail integration Verifi Email API Key - (https://verifi.email) Google Sheets - Pre-configured with 3 tabs (template provided) 5-10 minutes - Quick setup with step-by-step instructions included 📈 Benefits ✅ Improve Email Deliverability - Remove invalid emails before sending campaigns ✅ Reduce Bounce Rates - Only send to verified, active email addresses ✅ Save Money - Don't waste email credits on invalid addresses ✅ Better Analytics - Track conversion rates by source ✅ Professional Onboarding - Personalized welcome experience ✅ Scalable Solution - Handles high-volume sign-ups automatically ✅ Data Quality - Build a clean, high-quality subscriber list 🎨 Customization Options Email Template - Fully customizable HTML design Verification Threshold - Adjust score requirements Brand Colors - Match your company branding Confirmation Flow - Add double opt-in if desired Multiple Sources - Track different signup forms Language - Easily translate email content 📦 What's Included ✅ Complete n8n workflow JSON (ready to import) ✅ Google Sheets template structure ✅ Responsive HTML email template ✅ Setup documentation with screenshots ✅ Troubleshooting guide ✅ Customization examples 🔒 Privacy & Compliance GDPR-compliant with unsubscribe links Secure data handling via OAuth2 No data shared with third parties Audit trail in Google Sheets Easy data deletion/export 💡 Quick Stats 12 Nodes - Fully automated workflow 3 Data Paths - Valid, invalid, and incomplete submissions 100% Uptime - When properly configured Instant Processing - Real-time email verification Unlimited Scale - Based on your API limits 🏆 Perfect For Marketing Agencies SaaS Companies Content Creators E-commerce Stores Community Platforms Educational Institutions Membership Sites Newsletter Publishers 🌟 Why Use This Workflow? Instead of manually verifying emails or dealing with bounce complaints, this workflow automates the entire process from sign-up to welcome email. Save hours of manual work, improve your email deliverability, and create a professional first impression with every new subscriber. Start building a high-quality email list today! ---
Add Project Tasks to Google Sheets with GPT-4.1-mini Chat Assistant
Let your team create, track, and manage project tasks through natural conversation. This workflow uses an AI Project Manager Agent that chats with users, gathers the task details it needs, and automatically adds them to a Google Sheet. --- ✅ What this template does Lets you chat naturally with an AI to add new project tasks Automatically detects if the user wants to create or update an item (updates coming soon) Collects Task, Description, and Status fields — allows “don’t know” responses Appends new entries directly into your connected Google Sheets Provides real-time confirmation when the task is added > Trigger: n8n Chat Trigger > Integrations: OpenAI GPT-4.1-mini + Google Sheets (OAuth2) --- 🧠 How it works The Chat Trigger starts a chat with the user. The AI Project Manager Agent asks guiding questions to gather the task name, description, and status. When all fields are complete (all Info = Yes), the data is passed to the Google Sheets node. The task is automatically added to your project tracker sheet. The AI confirms completion in chat. --- ⚙️ Setup instructions Connect OpenAI Go to OpenAI Platform → copy your API key. In n8n, create New Credentials → OpenAI API and paste your key. Ensure your account has active billing under OpenAI Billing. Connect Google Sheets (OAuth2) In n8n → Credentials → New → Google Sheets (OAuth2) Sign in with your Google account and grant access. Select your spreadsheet and tab (e.g., “Tasks”) when prompted. Example sheet: https://docs.google.com/spreadsheets/d/1pbK-B-Q9p8fVjxJIsjEVrAfRgqEPCeYw8rZojZPAb84/edit Test your chat Click Execute Workflow, then start chatting: > “Add a task for reviewing the project report tomorrow.” The agent will ask questions if needed, then add the record to your sheet. --- 🧩 Customization ideas Add a Date Added or Assigned To column to the Google Sheet Integrate with Slack or Outlook to message assigned users Extend the agent to support task updates and deletes Replace Google Sheets with Airtable or Notion if preferred --- 🪄 Requirements n8n version ≥ 1.100 OpenAI API key Google Sheets account --- 📬 Contact Need help customizing this (e.g., adding deadlines, linking to Notion, or Slack notifications)? 📧 robert@ynteractive.com 🔗 Robert Breen 🌐 ynteractive.com
Automatic Gmail unsubscribe detection with AI and Google Sheets contact management
Automatically detect unsubscribe replies in your outreach emails and clean your Google Sheets contact list; keeping your domain reputation and deliverability strong. --- 🎯 Who it’s for This template is designed for freelancers, lead generation specialists, and outreach managers; particularly those running email outreach campaigns for clients or personal lead-gen projects. If you send cold emails, manage multiple lead lists, or handle outreach at scale, this workflow helps you automatically manage unsubscribe requests to maintain healthy email deliverability and protect your domain reputation. --- ⚙️ How it works Trigger: The workflow starts when a new reply is received in your Gmail inbox. Intent Detection: The email text is analyzed using OpenAI to detect unsubscribe intent (“unsubscribe”, “remove me”, “opt out”, etc.). Normalization & Filtering: A Code node verifies the AI output for accuracy and ensures the result is standardized as either "unsubscribe" or "keep". Check & Update Sheets: If the contact requested removal, the workflow checks your Unsubscribe Sheet to see if they’re already listed. If not, the contact is added to the Unsubscribe Sheet and simultaneously removed from your Main Outreach Sheet. Optional Gmail Label: Adds an “Unsubscribe” tag in Gmail for quick visual tracking (optional customization). --- 🧩 Requirements To run this workflow, you’ll need: Gmail Credentials → for reading incoming replies and applying labels. Google Sheets Credentials → to manage both the “Main” and “Unsubscribe” spreadsheets. OpenAI API Key → used for detecting unsubscribe intent from message text. All credentials can be added through the n8n Credentials Manager. --- 🧠 How to Customize Polling Time: Adjust how often the Gmail Trigger checks for new replies (default: every 5 minutes). Sheets: Replace the linked Google Sheets IDs with your own. You can change sheet names and columns freely. Intent Rules: Modify the Code node to include additional unsubscribe phrases or alternate keywords. Optional Gmail Tagging: Enable or disable tagging for unsubscribed messages. Secondary Validation: Enable the second “If” check after the OpenAI node to double-confirm unsubscribe intent before moving contacts. --- 💡 Why this workflow matters By automatically managing unsubscribe requests, you: Respect recipients’ opt-out preferences Reduce spam complaints Protect your domain reputation and increase deliverability Save hours of manual list cleaning This is a must-have automation for anyone running cold email outreach, especially freelancers managing multiple client inboxes. --- 🪄 Quick Setup Tips Replace all "Gmail account" and "Google Service Account account" credential references with your actual credentials. Ensure your sheet has an EMAIL column for lookup. Test with a few mock replies before activating for production. Optional: Add a time-based trigger to run the sheet cleanup periodically.