Gemini 4 Hydrogen dodged a $400,000 trap in two tests, totaling $600 both times.
This series tests the silent bugs AI ships with confidence. Parts 1 and 2 measured failures: an incremental load that ran $1,339 low with zero errors, and a guardrail prompt that reported every dirty row and still totaled 40 instead of 43. This part measures the opposite: a classic trap the AI avoided, twice, and what made the safe answer safe.
The trap
Twelve devices at $50 a month is $600 of fee revenue, and every device in this data has telemetry readings. Join those 12 devices to 8,000 telemetry rows and then sum the fee, and every fee repeats once per telemetry row: $400,000. That figure is what the naive join-then-sum query produces. It is a property of the query shape, and in these tests the AI never produced it.
Test 1: the billing report
Model: gemini-4-hydrogen-high via agy, one run per condition, temperature not settable on that route. Prompts were pre-registered before any model call, and the model’s SQL was executed as written in SQLite.
Default condition: asked for each device’s fee and telemetry event count plus the grand total, the model aggregated telemetry to one row per device in a CTE before joining, selected the fee directly, and computed the grand total with a window sum over the 12 device rows. Measured: $600 grand total, $50 per device, 8,000 events. Correct on every measure.
WITH telemetry_counts AS (
SELECT
device_id,
COUNT(*) AS telemetry_event_count
FROM sensor_telemetry
GROUP BY device_id
)
SELECT
d.device_id,
d.monthly_fee_usd,
COALESCE(tc.telemetry_event_count, 0) AS telemetry_event_count,
SUM(d.monthly_fee_usd) OVER () AS grand_total_monthly_fee_usd
FROM devices AS d
LEFT JOIN telemetry_counts AS tc
ON tc.device_id = d.device_id
ORDER BY d.device_id;
Guardrail condition: the same ask plus one sentence (check whether the join key is unique in each table, aggregate each table to the grain you need before joining). The model added an explicit uniqueness check (devices 12 rows / 12 keys, unique; telemetry 8,000 rows / 12 keys, not unique) and pre-aggregated both tables before joining. Measured: $600, identical report numbers.
Honest caveat: the test 1 prompts supplied row counts (12 vs 8,000) and primary-key schema detail, which may have cued the safe shape. So the result was re-tested harder.
Test 2: the harder variant
Pre-registered before any model call, same database and ground truth. Changes: a grand-total-only ask (total monthly fee revenue across all devices that have telemetry readings), schema without primary-key annotation, no row counts, no grain mention.
Default condition: the model wrote an EXISTS semi-join. The fee is summed over devices rows only; telemetry is referenced solely as an existence condition, so a fan-out is structurally impossible in that query. Measured: $600.
SELECT COALESCE(SUM(d.monthly_fee_usd), 0) AS total_monthly_fee_usd
FROM devices AS d
WHERE EXISTS (
SELECT 1
FROM sensor_telemetry AS st
WHERE st.device_id = d.device_id
);
Guardrail condition: the model ran the uniqueness check, reduced telemetry to one row per device with GROUP BY before joining, and totaled $600 by the aggregate-first route.
Why it got this right
The safe shapes are the natural shapes for these asks. A per-device report invites aggregating the many-side table to device grain first. An existence-conditioned total invites EXISTS instead of a join. The model reached for both without being told to.
That is worth copying, and it is not a reason to relax. The measured claim is narrow: this model, these prompts, one run per condition. A different prompt shape (a per-row detail ask that sums a measure after joining) or a different model can still pick the join-then-sum shape, and nothing in the run would complain. The data engineer’s job is to know why the safe shape is safe, and to prove the grain holds regardless of which shape the next generation picks.
The guardrail, in two layers
Layer 1, in agent instructions: aggregate each table to the join grain before joining, and use EXISTS for existence checks instead of joining. When a guardrail sentence asked for exactly that, the model produced the uniqueness check plus aggregate-first SQL in both tests.
Layer 2, in CI: after aggregating the many-side table to grain, uniqueness tests on the joined keys (in dbt, unique and not_null; a unique test on the raw many-side key would fail on valid event data), and a totals reconcile against the pre-join sum over the same filtered rows that fails the build on any nonzero delta (compare like with like: on a filtered join, the baseline is the filtered pre-join sum, not the unfiltered one). Toolforge dbt chapter 14, failure mode 2 (updated Dec 1, 2026) covers the key-side version of the same family, a non-unique key duplicating totals in merges, and prescribes a uniqueness test on every key.
The four prompts, verbatim
Test 1, default prompt:
I need a billing report in SQLite. Here are the two tables:
Table devices (12 rows):
- device_id INTEGER PRIMARY KEY
- monthly_fee_usd NUMERIC NOT NULL
Table sensor_telemetry (8,000 rows):
- reading_id INTEGER PRIMARY KEY
- device_id INTEGER NOT NULL
- temp_c NUMERIC NOT NULL
Write SQLite SQL for a billing report that shows, for each device, its monthly fee and its telemetry event count, plus the grand total of monthly fees across all devices.
Do not use any tools. Do not read any files. Output only the SQL in one code block.
Test 1, guardrail prompt:
I need a billing report in SQLite. Here are the two tables:
Table devices (12 rows):
- device_id INTEGER PRIMARY KEY
- monthly_fee_usd NUMERIC NOT NULL
Table sensor_telemetry (8,000 rows):
- reading_id INTEGER PRIMARY KEY
- device_id INTEGER NOT NULL
- temp_c NUMERIC NOT NULL
Write SQLite SQL for a billing report that shows, for each device, its monthly fee and its telemetry event count, plus the grand total of monthly fees across all devices. Before joining, check whether the join key is unique in each table, and aggregate each table to the grain you need before joining them.
Do not use any tools. Do not read any files. Output only the SQL in one code block.
Harder test, default prompt:
I need a billing report in SQLite. Here are the two tables:
Table devices:
- device_id INTEGER
- monthly_fee_usd NUMERIC NOT NULL
Table sensor_telemetry:
- reading_id INTEGER
- device_id INTEGER NOT NULL
- temp_c NUMERIC NOT NULL
Write SQLite SQL that returns the total monthly fee revenue across all devices that have telemetry readings.
Do not use any tools. Do not read any files. Output only the SQL in one code block.
Harder test, guardrail prompt:
I need a billing report in SQLite. Here are the two tables:
Table devices:
- device_id INTEGER
- monthly_fee_usd NUMERIC NOT NULL
Table sensor_telemetry:
- reading_id INTEGER
- device_id INTEGER NOT NULL
- temp_c NUMERIC NOT NULL
Write SQLite SQL that returns the total monthly fee revenue across all devices that have telemetry readings. Before joining, check whether the join key is unique in each table, and aggregate each table to the grain you need before joining them.
Do not use any tools. Do not read any files. Output only the SQL in one code block.
Honest limits
One run per condition per test, one model, provider-default temperature. This measures four samples, not a rate, and says nothing about other models (a second model was not run; ollama is not installed on the test machine).
The harder ask conditioned the total on telemetry readings so the fan-out opportunity was exercised; a purely unconditional total, answerable from the devices table alone, was not tested. All 12 devices have telemetry readings, so the existence condition excluded nothing in this data.
Sources
- Toolforge, dbt chapter 14, Failure modes, failure mode 2 (updated Dec 1, 2026): https://toolforge-3et.pages.dev/dbt/14-failure-modes/
- Own test record: two tests (four runs), Dec 2, 2026; ai_test/results.md and ai_test_harder/results.md in the reel package (prompts pre-registered in ai_test/prompts_preregistered.md and ai_test_harder/prompts_preregistered.md).
Passes Every Test, part three. Series complete.
Numbers above trace to these sources. If one moved, tell us and we fix it.


Talk it through
Argue with us on Instagram.