An AI analyst that shows its work
SQLly's notebook AI: six modes with budgets, findings labelled with evidence, SQLly's own checks first, proposals you approve, and no way to write.
I use LLMs for plenty of grunt work on SQLly. What I don't trust is an AI that answers a data question with a confident paragraph and no way to check it. "Revenue dropped because of the German market" is useless to me unless I can see which query said so, on which data, and whether that data was complete.
So the AI cell in SQLly notebooks is built around evidence and limits. It's the seventh post in the notebooks series. What follows is what it does, what it shows you, and what it can never do.
The Germany freight investigation from this post. The AI answers are a saved run of a local qwen2.5-coder model, replayed in the app, not a live call: the findings, their evidence, the queries it ran, and a proposal applied. Watch the whole recording, with chapters.
Six modes, each with a budget
An AI cell takes a question about the notebook and a mode. It uses whatever AI provider you've set up for the rest of SQLly. A local model through Ollama or MLX runs straight away. A cloud model asks first, which I'll get to.
| Mode | What it does | Default budget |
|---|---|---|
| Assist | Explain an error, complete or fix SQL, suggest a chart or read a plan. | 3 queries, 1,000 rows, 30 s of query time, 8 turns |
| Plan | Writes an investigation plan for you to approve. Nothing runs. | No queries, 8 turns |
| Build | Turns a request or an approved plan into proposed cells, edits and runs. | No queries, 8 turns |
| Investigate | Runs a few read-only queries, iterates, and reports findings with evidence. | 8 queries, 5,000 rows, 60 s, 12 turns |
| Review | SQLly's own checks first, then the model reviews the SQL. | 4 queries, 2,000 rows, 60 s, 12 turns |
| Explain changes | Says what changed between a recorded run and now (or another run), or since the AI last read each cell, and why. | No queries, 8 turns |
Every mode also has a 40,000-token budget. The cell shows a meter for queries, rows, query time, tokens and turns ("Queries 2 of 8"), plus the cost when the provider has prices set ("Cost $0.09 of $0.50"). Limits are checked before each step, a query's row limit is cut to whatever's left, and once a budget is spent the agent is told to wrap up. Stop ends it any time. Run All passes over AI cells without starting a model, so a full notebook run never quietly spends tokens.
Every finding says what it rests on
Findings come labelled: Observed fact, Derived metric, Hypothesis or Recommendation. Each one links to its evidence, either a cell and the run it read, like "by_country · run 3f2a…", or a query the agent ran, like "query q1".
The part I care about: SQLly decides whether a finding is verified, not the model. A finding is marked Unverified, with the reason, when nothing was run, when it cites no evidence, when it cites a result the agent never read, when the value it quotes isn't in its evidence, or when it rests on sampled or partial data, including a query cut off at its row limit. If two findings give different values for the same thing, both are kept and marked "Contradicted by …". You decide which one to believe.
Review runs SQLly's checks before the model sees anything
In Review mode, SQLly checks each query itself first and shows the results as "SQLly check: …". It looks for totals inflated by a join that repeats rows, COUNT(*) over joins, SUM or AVG of DISTINCT, out-of-date or reused results, sampled or partial data, cells that skip a filter the rest of the notebook applies, server-clock functions like GETDATE() and NOW(), cells allowed to change data, and sensitive-looking columns.
The fanout check is the one I'd point at first. Sum o.Freight across orders joined to order lines and every order's freight counts once per line. On Northwind, that join returns 2,155 lines for 830 orders. The check confirms the repeat from the cell's own results when the join key repeats, and then the model gets to explain it.
It proposes, you apply
The agent never edits the notebook directly. Everything it wants is a proposal listed under the answer, like "Insert 3 cells after by_country", "Edit orders" with a line diff, or "Run by_country". Accept or reject each one, then Apply accepted applies them as one group. New cells start read-only and carry an AI badge naming the cell that proposed them. Undo AI changes reverses the whole group in one step.
Each proposal is checked again when you apply it. Anything that would change data, edit a cell that's allowed to change data, edit the AI cell itself, move a cell to local data or another connection, or doesn't fit the cell kind's settings shows up as "Refused by SQLly" with the reason. Settings changes show in the proposal's diff too, so nothing slips in under a harmless-looking edit.
What it can never do
It can't write. There's no tool that changes data, and every query it runs has to be a SELECT for that connection's engine, on a read-only session. It can't export or reach the network. There's no export, send or HTTP tool, and asking for one gets "Unknown tool". It can't pick its own connections. It queries only the notebook's connections that your trust allows, whatever text in a cell or a result says.
Text in your data can't widen what it's allowed to do. Cell text, errors, column names and sample rows reach the model fenced off as data, with invisible characters stripped and the fence markers defused, so text in a cell can't close the fence early and pass itself off as instructions. It can still be misled by what it reads, like any model. That's why findings need evidence and changes need your OK, and why what it may query is decided by SQLly's code from your trust settings, never by the model. And each run goes into a local action log in SQLly's data folder, readable only by you: the mode, provider and model, every tool call and query with hashes of its arguments and results, the budget used and your approvals. Prompts and data aren't written there, only their hashes.
Cloud models ask before anything leaves
With a cloud model, the first run in a notebook stops at "Share this notebook's context with …?" and shows exactly what the first request will send, how many rows and queries the agent's tools may add later, and a Never sent list: credentials and anything that looks like a password, key or token, the values of sensitive parameters, and the values of sensitive-looking columns. Nothing leaves until you press Share and run. That consent is kept for this notebook and provider on this computer only, never in the file.
Where it's weaker than I'd like
The agent can read through production connections, like SQLly's other AI features, unless the production read lock is on. It can never write to them, but reading may still be more than you want, so turn the lock on if it is. Token counts are estimates, and so is the cost. The cost limit only works once you type your provider's prices per 1,000 input and output tokens into its profile in Settings, because SQLly never looks prices up. Without them the meter says the cap can't apply. Undo AI changes lasts for the tab's session and doesn't survive a restart. Explain changes can only pick from the newest 200 runs. The action log is written but not shown in the app yet.
The fanout check relies on key names like id, CustomerID and customer_id and on qualified columns, so it can miss a join it doesn't recognize. The ambiguous-term check only knows English. And AI cells only run in the desktop app. The browser build doesn't have them, and sqlly-cli skips them.
The modes, budgets and guarantees are all on The AI notebook agent. The evidence it links to comes from the run history in the previous post, and the next one is about exports, where unverified findings stay labelled. If you catch the agent claiming something its evidence doesn't support and SQLly doesn't flag it, send me the notebook.