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: 1. Captures a plain-language question from a chat widget or internal portal. 2. Fetches the current table + column sche...
Template notes
Give business users a chat box; get back valid BigQuery SQL and live query results. The workflow:
1. Captures a plain-language question from a chat widget or internal portal. 2. Fetches the current table + column schema from your BigQuery dataset (via INFORMATIONSCHEMA). 3. 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. 4. Executes the AI-generated SQL in BigQuery and returns the results. 5. 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
1. Import the workflow - n8n → Workflows → Import from File (or Paste JSON) → Save
2. 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) |
3. Point the schema fetcher to your dataset - In Google BigQuery1 you’ll see: sql SELECT tablename, columnname, datatype FROM n8nautomation-453001.emailleadsschema.INFORMATIONSCHEMA.COLUMNS - Replace n8nautomation-453001.emailleadsschema with YOURPROJECT.YOURDATASET. - Keep the rest of the query the same—BigQuery’s INFORMATIONSCHEMA always surfaces tablename, columnname, and datatype.