Guide

Using AI for data analysis safely

An AI assistant can draft a query that runs and still gives the wrong answer. Use the BigQuery check kit to see five ways that happens, then use the boundary policy to decide what your team can share and who signs off on the results.

Where AI helps in data work

Start with structured, reviewable work. Ask AI to draft SQL, explain unfamiliar code, write dbt model and column descriptions, summarise a redacted incident timeline or propose test cases. Give it the table grain, metric definition and expected output so a teammate can review the draft against the same brief.

Keep correctness and release decisions with people. A reviewer decides whether the number is right, the metric owner approves changes to business logic, and someone signs off before a figure reaches a stakeholder. An incident summary can suggest causes for a human to confirm against the evidence.

Five ways AI-generated SQL gets numbers wrong

Paste the downloaded script into the BigQuery SQL editor and run it as-is. Each example is a standalone GoogleSQL statement with fictional rows defined inline. Open the results for each statement and check that catches_error and verified are both true. The first means the check detects the flawed query and the second means the corrected query matches the known answer.

Fan-out joins inflate an order total

Two lines belong to order 1 and one belongs to order 2. Joining to the lines produces three rows at line grain and counts the first order twice. Use EXISTS to keep one row per qualifying order. Reconcile both the order count and the amount.

WITH orders AS (
  SELECT 1 AS order_id, NUMERIC '100' AS amount UNION ALL
  SELECT 2, NUMERIC '50'
), lines AS (
  SELECT 1 AS order_id, 1 AS line_no UNION ALL
  SELECT 1, 2 UNION ALL SELECT 2, 1
), before_fix AS (
  SELECT COUNT(*) AS rows_at_grain, SUM(o.amount) AS total
  FROM orders AS o JOIN lines AS l USING (order_id)
), after_fix AS (
  SELECT COUNT(*) AS rows_at_grain, SUM(o.amount) AS total
  FROM orders AS o
  WHERE EXISTS (SELECT 1 FROM lines AS l WHERE l.order_id = o.order_id)
)
SELECT b.rows_at_grain AS before_rows, a.rows_at_grain AS after_rows,
  b.total AS before_total, a.total AS after_total,
  2 AS expected_rows, NUMERIC '150' AS expected_total,
  (b.rows_at_grain <> 2 OR b.total <> NUMERIC '150') AS catches_error,
  (a.rows_at_grain = 2 AND a.total = NUMERIC '150') AS verified
FROM before_fix AS b CROSS JOIN after_fix AS a;

Expected: 3 rows and 250 before, 2 rows and 150 after.

COUNT(*) counts rows, even when you asked for customers

One customer placed two orders. Count distinct customer IDs to answer how many identified customers ordered. If unknown IDs matter to the metric, agree how to handle them explicitly.

WITH orders AS (
  SELECT 10 AS customer_id UNION ALL
  SELECT 10 UNION ALL SELECT 20
), answers AS (
  SELECT (SELECT COUNT(*) FROM orders) AS before_value,
    (SELECT COUNT(DISTINCT customer_id) FROM orders) AS after_value
)
SELECT before_value, after_value, 2 AS expected_value,
  before_value IS DISTINCT FROM 2 AS catches_error,
  after_value IS NOT DISTINCT FROM 2 AS verified
FROM answers;

Expected: 3 order rows before, 2 customers after.

A WHERE filter silently drops NULLs

The rule excludes known test records and keeps records whose category is unknown. For an unknown category, category != 'test' evaluates to NULL, which WHERE discards. IS DISTINCT FROM implements the agreed rule.

WITH records AS (
  SELECT 'live' AS category UNION ALL
  SELECT 'test' UNION ALL SELECT CAST(NULL AS STRING)
), answers AS (
  SELECT (SELECT COUNT(*) FROM records WHERE category != 'test') AS before_value,
    (SELECT COUNT(*) FROM records WHERE category IS DISTINCT FROM 'test') AS after_value
)
SELECT before_value, after_value, 2 AS expected_value,
  before_value IS DISTINCT FROM 2 AS catches_error,
  after_value IS NOT DISTINCT FROM 2 AS verified
FROM answers;

Expected: 1 record before, 2 records after.

UTC dates move events across reporting days

The report uses the New York calendar day. The first event is on the target day in New York and the second is exactly at the start of the next day. The UTC filter excludes both. Use the agreed time zone, including its daylight-saving rules.

WITH events AS (
  SELECT TIMESTAMP '2026-11-22 04:59:59+00' AS event_at UNION ALL
  SELECT TIMESTAMP '2026-11-22 05:00:00+00'
), answers AS (
  SELECT (SELECT COUNT(*) FROM events
  WHERE DATE(event_at) = DATE '2026-11-21') AS before_value,
    (SELECT COUNT(*) FROM events
  WHERE DATE(event_at, 'America/New_York') = DATE '2026-11-21') AS after_value
)
SELECT before_value, after_value, 1 AS expected_value,
  before_value IS DISTINCT FROM 1 AS catches_error,
  after_value IS NOT DISTINCT FROM 1 AS verified
FROM answers;

Expected: 0 events before, 1 event after.

Plausible SQL can implement the wrong metric

The agreed metric is captured revenue less refunds, measured in one currency. A 100 capture and a 30 refund yield 70. Check that the implementation applies the agreed refund rule, and test refund timing when you adapt the fixture.

WITH payments AS (
  SELECT 'capture' AS kind, 100 AS amount UNION ALL
  SELECT 'refund', 30
), answers AS (
  SELECT (SELECT SUM(amount) FROM payments WHERE kind = 'capture') AS before_value,
    (SELECT SUM(CASE kind WHEN 'capture' THEN amount
    WHEN 'refund' THEN -amount ELSE 0 END) FROM payments) AS after_value
)
SELECT before_value, after_value, 70 AS expected_value,
  before_value IS DISTINCT FROM 70 AS catches_error,
  after_value IS NOT DISTINCT FROM 70 AS verified
FROM answers;

Expected: 100 gross before, 70 net after.

Verify against known answers before sharing

Write the expected grain, population, time zone and metric formula before running the draft. Build a tiny fixture you can calculate by hand. Include a repeated key, a NULL, an event across midnight and any exception that can change the result, such as a refund. Record the expected answer independently of the generated SQL.

For real data, reconcile row counts and totals to a trusted source at the same grain, population and time window. Compare by key or by reporting slice as well as overall, since errors can cancel. For a result meant to have one row per order, group by order ID and check for any NULL key or group with COUNT(*) greater than one.

Save the definition, query version, comparison results and explanations for any differences alongside the review. When the query will run again, keep the fixture and grain checks as regression tests.

Decide what data may go where

Start with approved schemas, column types, lineage, redacted code and invented rows. Check metadata too. Table names can identify clients, logs can carry personal data, and SQL literals can contain real IDs. Review what the assistant can read through connectors, attachments and stored conversation history as well as what you paste.

Use row-level data only within an environment approved for that data and purpose. For personally identifiable information (PII) and contract-restricted data, check the applicable commitments with the people responsible for them. Confirm the service and account, who can access inputs, whether they are retained or used for training, and where they are processed before sharing.

Copy or download the template, replace the bracketed fields, then have your policy owner approve the destinations, sign-off rules and review date.

Download policy (.md)
# AI data-use boundary policy

- Team and scope: [people, workflows and environments covered]
- Policy owner: [name or role]
- Effective date: [YYYY-MM-DD] · Next review: [YYYY-MM-DD]

## Where data can go

- **Public or synthetic**: [approved public AI services]. Use published material or invented examples that contain no real identifiers or confidential details.
- **Internal metadata, code or aggregates**: [approved managed AI services and settings]. Share only what's needed. Review schema names, comments, query literals, logs and small groups for sensitive details before sending.
- **Confidential row-level data**: [approved restricted environment and use cases]. Use only with written approval from [data owner and security/privacy approver] and only within the approved project boundary.
- **PII and contract-restricted data**: [explicitly approved environment and conditions]. Keep out of AI services by default. Require written clearance for the specific data, use and destination. Never send credentials or secrets.

If a service, feature or data class is unlisted, ask [policy owner] before use. For managed or restricted services, record allowed accounts and connectors, retention and deletion settings, model training terms, data location and access controls. Check applicable customer contracts before approval.

## Human sign-off

[Reviewer role] approves AI-drafted SQL or tests before deployment. [Metric owner] approves metric logic changes and stakeholder-facing numbers or analysis before release. Attach the agreed definition, row-count and total reconciliation, grain check and known-answer results to [review location].

## Logging and review

Record the operator, date, use case, service, data class, output reference and reviewer decision in [access-controlled register]. Keep records for [retention period]. Avoid copying sensitive inputs into the register. Escalate accidental disclosures to [incident contact]. The policy owner reviews this document on the date above and whenever a service, contract or data class changes.

Questions

Related questions

How do AI and data analysis work together?

AI can draft SQL and documentation, explain code and propose checks. Analysts supply the metric definition, verify the query on known cases and reconcile the numbers before sharing.

Can AI do data analysis?

It can help explore data, draft a query or summarise results. Check its assumptions, verify the output against known answers and have a human reviewer approve the conclusion.

Is it safe to paste data into ChatGPT?

Use public or synthetic examples if your team approves the service. Before sharing internal or row-level data, confirm the account and feature are approved for its classification, retention and access settings, and contract terms.

Will AI replace data analysts?

AI can shorten drafting and documentation work. Analysts still define the question, resolve differences in business rules, verify results and explain what the numbers mean for a decision.

The Divergence Point — monthly

Where the numbers stop agreeing, and what to do about it. One email a month on data quality, reconciliation and building warehouses that survive contact with a real business. No recycled LinkedIn posts.

Tell me what is broken.

A short call is usually enough to tell whether this is a two-week fix or a two-month one — and whether I am the right person for it.