n8n

How to Connect Chat to BigQuery Analytics?

Chat questions turn into live answers from your data warehouse. An AI agent writes SQL and runs it on BigQuery, so operations and supply chain teams can check KPIs and trends in minutes. It is built for people who want fast insights without writing code.

Here is how it works. A chat window starts the flow and a short memory keeps context. The AI Control Tower Agent uses the OpenAI chat model to draft a query for the table and fields you define. Instead of sending SQL straight to BigQuery, the agent calls a custom query tool. That tool triggers a small sub workflow that receives the query, strips code fences with a Code node, and runs it in the Google BigQuery node. The raw results go back to the agent, which returns a clean reply in chat.

Setup is simple. Add OpenAI and Google BigQuery credentials, then update the system prompt with your dataset and field names. Expect faster answers, fewer BI tickets, and quicker standups. Use it for daily KPIs, on time delivery checks, lane performance, inventory snapshots, and quick data checks during meetings. Teams save time and reduce errors because the query is cleaned and executed in a repeatable way.

What are the key features?

  • Chat trigger collects user questions and starts the flow
  • Chat memory keeps recent context for follow up questions
  • AI Control Tower Agent uses the OpenAI chat model to write SQL
  • Custom tool workflow sends only the SQL string in a query key
  • Execute workflow trigger receives the query in the sub workflow
  • Code node removes code fences and cleans the SQL
  • Google BigQuery node runs the query and returns raw results
  • Reusable BigQuery sub workflow supports multiple agents

What are the benefits?

  • Reduce manual query work from hours to minutes
  • Eliminate common SQL formatting errors with query sanitizing
  • Streamline ad hoc reporting by up to 70 percent
  • Handle more requests with a reusable BigQuery tool
  • Connect chat and your data warehouse for faster decisions

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with OpenAI and Google BigQuery. See the Tools Required section above for links to create accounts with these services.
  3. Open the OpenAI Chat Model node, choose the model you prefer, then in the Credential to connect with dropdown click Create new credential and enter your OpenAI API key from the OpenAI API keys page.
  4. Open the AI Control Tower Agent node and update the system message with your dataset, table name, and field descriptions so the agent writes correct SQL.
  5. Open the Call Query Tool node and confirm the workflowId points to your BigQuery tool workflow. Ensure the input mapping sends the query key with the SQL string.
  6. Open the sub workflow used as the BigQuery tool and verify the Trigger node has an input field named query.
  7. Open the Google BigQuery node in the sub workflow, then in the Credential to connect with dropdown click Create new credential and add a Google Cloud service account JSON key with BigQuery Job User and BigQuery Data Viewer roles.
  8. In the BigQuery node, set the Project ID and any required dataset or location fields. Leave the SQL query field mapped to {{$json.query}}.
  9. Check the Code node named Sanitising the Query to ensure it strips ```sql and ``` and trims the SQL. Keep it enabled to avoid formatting errors.
  10. Open the Chat with the User trigger and click Test to start a session. Ask a question like How many shipments were delivered last week. Confirm you receive a result.
  11. If you see permission errors, confirm the service account has access to the project and dataset, and that the project ID in the node matches your Google Cloud project.
  12. If SQL returns syntax errors, update the agent system message to include exact table and field names and confirm the Code node is removing code fences.
  13. Optional replacement of the chat trigger: connect Telegram, Slack, or a webhook trigger and map incoming text to the agent input to use your preferred channel.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Google BigQuery

Sign up

Free usage tier: $0, first 1 TiB queries / mo and 10 GiB storage / mo (via BigQuery Free Tier/Sandbox)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.