How to Query a Warehouse With Hex AI in Your First Notebook

November 13, 2026

Hex AI writes SQL and Python against your warehouse from a plain-English prompt, inside a collaborative notebook. You connect a data source, type a question into the AI cell, run the generated query, then publish the notebook as an interactive app. First working query usually lands in under 10 minutes.

Hex is a notebook built for analytics teams rather than a chatbot bolted onto a SQL editor. Hex Magic, its AI layer, knows the schema of your connected warehouse, which is why the SQL it writes is far closer to correct than what you get pasting table names into ChatGPT.

What do you need before you start?

A warehouse connection with read access, and one table you understand. That is it for a trial.

Hex connects to Snowflake, BigQuery, Redshift, Databricks, Postgres and DuckDB. The free trial gives you a workspace without a credit card. Paid plans are quoted per seat; the Team tier starts in the low hundreds per month for small teams, and Enterprise adds SSO and row-level permissions.

If your data lives in spreadsheets, use the DuckDB or CSV upload path. It is a legitimate way to test whether the AI understands your domain before you ask for warehouse credentials.

How does the AI cell work?

Open a new project, click the plus to add a cell, and choose the AI option instead of SQL or Python. You get a prompt box, not a query editor.

A first prompt that works:

Using the orders table, show monthly revenue and order count for 2025, excluding refunded orders. Use created_at for the date.

Hex returns a SQL cell with the query and an explanation. You run it, look at the result, and either keep it or prompt again with a correction. The generated cell becomes a normal SQL cell you can edit — that is the important design choice. The AI is a starting point, not a locked black box.

Naming the table and the date column in the prompt cuts the failure rate sharply. When you leave those out, the model picks a plausible column name, and “did not exist” errors follow.

Which prompts produce SQL you can trust?

Prompts that state the grain, the filters and the metric definition. Vague prompts produce queries that run without error and answer the wrong question, which is worse than a crash.

Prompt style Result
“Show sales by month” Guesses which column is sales, may double count joins
“Monthly sum of amount from orders, one row per order_id, 2025 only” Usually correct on first run
“Revenue instead of refunded” Model adds a filter, may not match your finance definition

The most expensive mistake in AI SQL is a query that returns a believable number. Always sanity check totals against a dashboard your finance team already trusts before you forward anything.

How do you fix an AI query that is wrong?

Click the cell and prompt “this returns 12,000 rows but should be about 400; the join is probably fanning out.” Hex’s AI sees the query, the schema and the error or result context, so corrections on the second pass work far better than the first attempt.

Three fixes cover most failures:

  • Fan-out from joins — ask for a pre-aggregated CTE before the join
  • Wrong date column — name it explicitly; warehouses often have created_at, updated_at and order_date
  • Null handling — ask for coalesce on metrics and a where ... is not null guard

If the query fails with a database error, paste the error into the follow-up. The model reads it and adjusts.

How do you turn the notebook into something others can use?

Publish it as an app. Hex renders selected cells as charts and inputs, and anyone with the link can filter without seeing or editing code.

A practical pattern for a weekly report:

  1. One SQL cell parameterized by a date range input
  2. One chart per metric group
  3. A markdown cell at the top explaining what the numbers mean
  4. Publish to the app view and share the link, not the project

That single date filter turns a static dashboard into something the operations team opens on their own, which is the actual win. The analyst stops being a query service.

Where does Hex AI struggle?

Anything requiring business definitions the warehouse does not encode. If “active customer” means 90-day purchase history and that logic lives in an analyst’s head, the AI will approximate it and be wrong in a way nobody catches until a board meeting.

Complex window functions across several CTEs also come out brittle. The model writes something plausible, it runs, and the ranking logic is subtly off. Review window functions line by line.

Who should use Hex, and who should not?

Analytics teams already on a warehouse will get value in the first week, especially teams where 3-5 people write similar queries. The collaborative notebook plus AI is a real speedup for exploratory work.

Skip it if you are a solo analyst with one dashboard — a simpler BI tool costs less and does not need notebook literacy. Also skip it if you cannot give the AI schema access; without schema context, the SQL quality drops to generic chatbot level.

Does it replace knowing SQL?

No, and pretending otherwise is expensive. The teams that benefit most run the generated query, spot the join fan-out, and fix it in 30 seconds. People who cannot read SQL produce confident wrong numbers.

Quick Summary

  • Hex AI writes SQL and Python from prompts using your live warehouse schema.
  • A first working query typically takes under 10 minutes after connecting a source.
  • Generated cells remain editable SQL, so you can fix rather than regenerate.
  • Specify table, grain and date column in the prompt to avoid plausible-but-wrong results.
  • Without a warehouse connection or SQL literacy, the value drops sharply.
Tags: