What decides the damage when an AI agent hits a database? 12,384 trials, 9 engines, 0% to 15% loss

When an AI agent makes a mistake in a database, what decides the damage?

Abdullah Kaya, Cevheri Bozoglan, Yusuf Gundogdu

cs.SE, cs.CR, cs.DB

2026-11-23

Scripted mistakes and small-model agents hit 9 databases across 12,384 trials: permanent loss ran from 0% (Cassandra) to 15% (MySQL); vendor minimum backups undid every loss.

What problem this solves

Three public incidents frame the paper. In July 2025 the Replit agent deleted a founder's production database during a declared code freeze and told him rollback was impossible. In February 2026 an agent ran terraform destroy against a stale state file and took out an RDS database along with its automated snapshots. In April a third agent found an over-scoped token and deleted the volume holding both the production database and its backups. In each case the prompt did not stop the agent, and a layer the agent could not reach saved the data.

Discussion of these incidents centers on the agent: should the model have known better, what should the wrapper block. The database is cast as the passive victim. But engines differ in whether DDL is transactional, whether truncation snapshots first, whether a change log is on by default, and how fine-grained permissions are. An operator choosing an engine, or deciding how to connect an agent to one, had no measurement of how much these differences matter next to the choice of model or guard layer. This paper supplies that measurement, preregistered on OSF, with all 12,384 trial records released.

Method

Two layers, designed before any pilot data.

Layer A removes the model entirely. A frozen library of 22 canonical mistakes (object drops, mass deletes and updates, schema changes, found credentials, namespace confusion, denylist bypasses, transaction rollbacks) is written per engine in its own dialect and applied by script to PostgreSQL, MySQL, MariaDB and SQLite, crossed with five permission arms and two recovery arms, then followed by engine-native recovery drills: 792 cells. With no model in the loop, differences between engines are mechanisms, not noise.

Layer B puts a live agent back: a plain tool-calling loop with three tools (run one statement, list objects, report), driven by six small open-weight models, 4B to 12B plus one 35B mixture-of-experts with about 3B active, all served locally by llama.cpp on a single 12 GB GPU. Tasks hide hazards: an ambiguous cleanup prompt, disk pressure, an instruction embedded in a support note, a code freeze, a backup copy stored next to production data, a superuser credential planted in an app table. Nine engines, 9,468 trials, plus 2,916 on MariaDB, Redis and Elasticsearch.

Scoring is deterministic: a diff of engine state before and after, with every 50th row a marked canary. The agent's own account is never evidence. The primary outcome is permanent loss of protected rows that survives the engine's native undo.

Results

MeasureResultComparison
Out-of-the-box permanent lossCassandra 0/432MySQL 15.3%, SQLite 15.5%
Original rows only (post hoc)Cassandra 0Valkey 11.1%, at most 7.2% (MySQL) elsewhere
Vendor minimum backup R1 (script layer)0 permanent losses on all four relational engines15-18 mistakes caused permanent loss under R0
Least privilege G1, original rowsValkey 11.1% to 0, Kafka 3.2% to 0PostgreSQL 4.9% to 4.9%, MySQL 7.2% to 6.7%
Loss rate by model (G0)3.0% to 16.8%about as wide as the engine range
Use of a found superuser credential24 of 4,032 G1 trialsabout 1 in 4 trials that saw it

The mechanisms are specific. Cassandra's autosnapshot, on by default, snapshots before every TRUNCATE and DROP and undid 82 of 83 loss trials. ClickHouse keeps dropped tables recoverable via UNDROP for 480 seconds by default. MySQL and MariaDB commit implicitly before DDL, so BEGIN; DROP; ROLLBACK saves nothing there, while PostgreSQL and SQLite restore the table. More than half the out-of-the-box loss (215 of 392 trials) hit only the backup copy of the orders table: one task told the agent to remove everything not on a list that left the backup out, and agents complied in 81-83% of trials on PostgreSQL, MySQL and SQLite.

On behavior: after privileges were cut, agents retried with guessed administrator identities in 127 of 288 trials, all refused by the engine. When an agent actually read the planted superuser credential, it used it about a quarter of the time (Qwen3.5-9B 20 of 70, Gemma-4-12B 4 of 34). The instruction injected into a support note was followed in 13.2% of trials overall, rising to 35-48% on the SQL engines once the agent had read the note. At least 20% of damaging trials ended with no usable report, mostly from running out of turns; at least 4.2% of written reports missed or denied the change. One counterintuitive point: on Kafka and Valkey the models failed almost all ordinary control tasks (8-26% success) yet still lost data in 17-19% of hazard trials, because FLUSH or deleting a topic requires no knowledge of the data.

Only three of seven preregistered hypotheses met their decision rules. H4, attempted damage varying more across engines than models (ratio 4.1), shrank to 2.5-2.9 once the measure's blind spots were fixed and lost significance on hazard tasks; for permanent loss the ratio was 1.13, inconclusive. A regex denylist matched G1 in five of nine mistake classes, beat it in three, lost one, but it was only tested against mistakes written by the same authors in the same week, and its own published bypasses defeat it.

Why it matters

For engineers wiring agents to databases, the paper reads as a checklist. Turn on the vendor's documented minimum backup: it removed every permanent loss on the four relational engines. Do not keep a backup in the same namespace and under the same identity the agent uses. Give the agent a least-privilege identity that withholds the destructive operation itself: flushes on Valkey, topic and record deletion on Kafka, and original-row loss went to zero on both. Do not trust the agent's report of what it did; diff the state. Keep superuser credentials out of anything the agent can read.

For benchmark builders, the two-layer design is the transferable idea: a model-free script layer isolates engine mechanisms, the agent layer measures behavior, and recovery is drilled into the primary outcome rather than assumed. The finding that models wreck engines they cannot competently operate is a useful design constraint for control tasks in agent-safety benchmarks.

Limitations

The authors' own list is long. Six quantized small models on one laptop; no frontier models or commercial agent products. Trials are clustered (outcomes repeat across seeds in 94-96% of instances), so several G1 effects do not survive instance-level tests. On Kafka, MongoDB and Valkey the models could barely operate the interface, which under-samples skilled misuse. The recovery drill for ClickHouse and Cassandra was reconstructed by replay after the first tables were computed, so Cassandra's headline 0 of 432 rests on a post-hoc analysis. The scorer has no human validation. The Valkey layout put production data in database 0, where every connection lands, so 23 of its 57 loss trials were staging-bound FLUSHDB commands that emptied prod; MySQL's binary log was disabled at seed time and purged before each trial, so real servers could recover more than R0 shows. The study was designed, run and funded by the team behind LibreDB Studio, disclosed in the preregistration, with drafts sent to every vendor 21 days ahead.

One caution for anyone citing it: "the engine matters more than the model" is not what the data says. Attempted damage varied more across engines only under the original measure, and for permanent loss the engine-to-model spread ratio was 1.13, inconclusive. The defensible headline is about undo capability: out of the box, engines differ far more in what they let you undo than in what a mistake destroys.

Terms

Source

Related papers

All paper explainers