← Blog

Technical brief

Data agents still write subtly wrong SQL.

Here’s how Vuon checks agent-authored SQL, with a worked example.

Vuon 5 min read

Most wrong answers from a data agent don’t come from SQL that fails. They come from SQL that succeeds.

The query parses. The warehouse returns a number. The agent writes a confident sentence around it. But the number counts duplicate events, includes placeholder accounts, or double-counts orders through a join. None of those mistakes produces an error. They quietly send the agent in the wrong direction and lead to conclusions that are less accurate than they look.

Vuon is built to catch this category of mistake. The agent writes SQL freely. Before the answer reaches you, or the data reaches back to the agent, Vuon checks the query against what your team has declared about the data in the semantic layer, and gives the agent specific feedback when the two disagree.

A simple example

Someone asks: what was our revenue in October, and how much did we refund? Orders and refunds live in two tables, and an order can be refunded more than once:

shop.orders
order_idorder_total
1001$100
1002$80
shop.refunds
refund_idorder_idrefund_amount
r11001$20
r21001$30

A capable model will often write something like this. Vuon flags it before it runs:

The agent’s first query
SELECT
SUM(o.order_total) AS revenue,
SUM(r.refund_amount) AS refunded
FROM shop.orders o
LEFT JOIN shop.refunds r
ON r.order_id = o.order_id
WHERE o.ordered_at >= '2026-10-01'
AND o.ordered_at < '2026-11-01'
Warningline 2 · SUM(o.order_total)
Join fanout: SUM(…) AS revenue can count a row more than once: by the declared relationship, the join to shop.refunds (r) on r.order_id can return several rows for each row of shop.orders (o) (shop.refunds.order_id → shop.orders.order_id declared many_to_one). Aggregate shop.refunds (r) to one row per r.order_id in its own CTE or subquery before joining it, or compute SUM(…) AS revenue from shop.orders (o) before the join.

The query looks reasonable, and it would run without complaint. But joining refunds onto orders repeats every order that has more than one refund:

On the example data
Agent’s revenue
$280
Actual revenue
$180

Order 1001 has two refunds, so the join returns it twice and its $100 is counted twice. The refund total, $50, is still right, which makes the result look plausible.

A data scientist would likely spot this. An agent answering dozens of questions an hour, often for people who never read the SQL, frequently doesn’t. The warning above is the actual output of Vuon’s checker for this query.

1. Record what the data means

The check works because the semantic layer says how these tables relate. Many refunds can point at one order:

Declared in the semantic layer (simplified)
{
"dataset": "shop.refunds",
"primaryKey": "refund_id",
"joins": [{
"to": "shop.orders",
"localField": "order_id",
"foreignField": "order_id",
"relationship": "many_to_one"
}]
}

Teams usually already know facts like this. Vuon makes them inputs to the checker, not just notes for the model to read.

2. Analyze the query the agent wrote

Vuon parses the SQL into a syntax tree and follows values through aliases, CTEs, subqueries, and joins. It doesn’t look for keywords or guess from column names. For the first query, it establishes:

  • SUM(o.order_total) adds up rows of shop.orders.
  • The query joins shop.refunds to those rows on order_id.
  • The semantic layer declares that many refunds can belong to one order.
  • So the join can repeat an order, and the sum can count it more than once.

That produces the warning, pinned to the exact expression at risk, along with a concrete way to fix it.

3. The agent revises

The agent gets that feedback before relying on the result. Following it, the agent totals refunds per order first, so the join can’t repeat an order:

Revised query
WITH refunds_per_order AS (
SELECT order_id,
SUM(refund_amount) AS refunded
FROM shop.refunds
GROUP BY order_id
)
SELECT
SUM(o.order_total) AS revenue,
SUM(r.refunded) AS refunded
FROM shop.orders o
LEFT JOIN refunds_per_order r
ON r.order_id = o.order_id
WHERE o.ordered_at >= '2026-10-01'
AND o.ordered_at < '2026-11-01'

The warning clears, and the query returns $180 in revenue and $50 in refunds. The answer stays tied to its SQL, so a reviewer can see the final query, the check result, and how the agent got there.

Why not just put this in the prompt?

You can. It helps, but it isn’t a check. Prompt context tells the model what might matter. It doesn’t tell you whether the model applied it in the query it ran. A model can read the right paragraph and still write the more natural-looking join.

Vuon separates two jobs:

  1. Generation: the model writes whatever SQL best answers the question.
  2. Validation: deterministic analysis checks that SQL against what has been declared about the data.

The model keeps its flexibility. Your team’s knowledge becomes part of the execution path. We made the architectural case in Let the Agent Write the SQL. Then Validate It.

The same pattern covers other traps

Join fanout is one example. The same approach catches other common sources of plausible but wrong answers:

Dropped rows
An inner join to subscriptions silently removes active accounts that have no subscription.
Date cutoffs
created_at <= '2026-09-30' stops at midnight and misses almost all of September 30.
Duplicate events
If an event can be logged twice, counting rows overstates activity.
Historical validity
A subscription active at month end needs a different filter from one created during the month.
Re-saved records
A new version row can be a save that changed nothing, not a real edit.

Some checks need nothing but the SQL. Others depend on facts declared for a specific dataset. Vuon doesn’t need a universal rule for every warehouse. It needs a way to make your warehouse’s exceptions operational.

What we measured

We compared a baseline agent, with BigQuery access and schema documentation supplied as skills, against Vuon’s full system: agent, catalog declarations, and SQL checker. Model and reasoning effort were held constant within each comparison.

Across 405 runs per system, Vuon answered 81.7% correctly, against 64.7% for the baseline. The largest gap was on questions where a data quirk changed the answer: 74.4% against 48.3%, or about 54% more correct answers. Read the benchmark and methodology.

What this doesn’t guarantee

A checker can’t establish that an answer is right in every sense. It only knows the rules that have been declared, and it can’t decide what a stakeholder meant by an ambiguous question. Some findings are warnings because the right choice depends on the question; others can be configured to block a query before it runs.

That’s the right boundary. The model reasons. The checker makes known facts about the data hard to ignore. People can see and review the work. That matters most where data is messy: the places where a query can run successfully and still produce the wrong number.

See Vuon on your data →