---
title: Your GA4 Interface Is a Summary. Put an LLM Agent on the BigQuery Export, With Guardrails.
description: An LLM agent on your GA4 BigQuery export answers questions the interface cannot, but only if it queries curated views with cost caps and a test set. Here is the setup that keeps the numbers right.
author: LETSGROW Dev Team
date: 2026-10-08
category: Analytics
tags: ["GA4", "BigQuery", "LLM Agents", "Text-to-SQL", "Marketing Analytics"]
url: "https://letsgrow.dev/blog/ga4-bigquery-export-llm-sql-agent-guardrails"
---
Letting an LLM write SQL against your GA4 BigQuery export is the best analytics upgrade a small marketing team can make this year, and also the fastest way to ship confident, wrong numbers. The agent is not the hard part. The guardrails are. Teams that skip them get a chatbot that answers every question and is right some unknown fraction of the time.

My position: connect an agent to the raw export, but only through a thin layer of views you control, with hard cost caps and a test set. Do that and you get answers the GA4 interface cannot give you. Skip it and you are guessing faster.

## Why the Export Beats the Interface

The GA4 interface is a summary layer. Reports apply thresholds, cardinality limits, and sampling on heavier explorations, and custom questions mean waiting on an analyst. The BigQuery export is the event-level source: one row per event, with every parameter attached. It is free to turn on, though standard properties cap the daily export at one million events, so check your volume before you rely on it.

That event-level data is exactly what a language model is good at querying, because the questions marketers actually ask are awkward in a UI and trivial in SQL. Which landing pages produce sessions that reach a demo form in under three visits? Which campaigns drive users who return within seven days? Plain English in, a query out, an answer in seconds.

## Why a Naive Agent Fails

Point a model at the raw tables and three things go wrong. First, GA4 stores event parameters as nested, repeated fields, so every useful query needs an UNNEST. Models get this wrong in subtle ways that still return plausible numbers. Second, there is no session table. Sessions are reconstructed from a session id plus a user pseudo id, and the model will invent its own definition unless you hand it one. Third, the export has intraday and daily tables with different completeness, and a careless wildcard query mixes them.

None of these throws an error. They produce a clean chart with the wrong total, which is worse than a failure because someone will present it.

::compare-table
| Approach | Setup effort | Accuracy risk | Cost control |
| --- | --- | --- | --- |
| Agent on raw export tables | Low | High, wrong UNNEST and session logic | Weak, full scans possible |
| Agent on curated views | Medium | Low, definitions are fixed once | Strong, views limit scanned columns |
| Pre-built dashboards only | Medium | Low | Strong, but no ad hoc questions |
| Analyst tickets | None | Low | Strong, but days of latency |
::

## Build the Guardrails First

The fix is a semantic layer made of plain SQL views. Create a sessions view with your one agreed session definition. Create an events view that flattens the five or six parameters you actually use, such as page location, campaign source, and form name. Define conversions once. The agent gets read access to these views and nothing else, so it cannot reinvent your metrics or touch the raw tables.

Then cap the blast radius. Give the agent its own service account with read-only access to one dataset. Set a maximum bytes billed on every query so a bad scan fails instead of costing money. Require a dry run before execution and log every generated query with its result. Partition filters on the event date should be mandatory, not suggested.

Finally, write the test set. Pick 20 questions where you already know the answer from a trusted report, run them through the agent, and compare. If it cannot reproduce numbers you can verify, it does not get the unverified ones.

::checklist
title: "Before an agent touches your GA4 export"
items:
  - Sessions and conversions are defined once in views, not left to the model
  - The agent can read the curated dataset only, never the raw export tables
  - Every query has a maximum bytes billed cap and a required date filter
  - Generated SQL is logged and shown next to every answer
  - 20 known-answer questions pass before launch and rerun after schema changes
::

## Make the Answer Auditable

Always show the SQL beside the result. Marketers do not need to read it every time, but the one analyst who does will catch the error that matters. Add a plain sentence stating the date range, the session definition, and the row count behind each answer. If the agent cannot state these, treat the answer as a draft.

Expect to maintain it. Event names change, new parameters appear, and a new tagging release can silently break a view. Rerun the test set whenever the tracking plan changes, the same way you would rerun tests when code changes.

## The Takeaway

Do three things this week. Turn on the BigQuery export if it is not running. Write two views, one for sessions and one for flattened events. Then give an agent read access to those views only, with a bytes cap, and score it against questions you can already answer. The model is a commodity. Your definitions, limits, and tests are the product.
