When an AI Agent Deletes Your Database, Your Database Settings Decide the Damage
A new study ran about 12,000 agent trials across a dozen databases. What saved the data was usually a backup the agent could not reach.
Every story about an AI agent deleting a production database gets told the same way. The model went rogue, the prompt was too loose, the guardrails failed. We argue about which model would have known better.
But look at how those stories end. The data almost always comes back, and it comes back from somewhere the agent could not reach.
A preregistered study posted to arXiv on November 23 took that pattern seriously and measured it. "When an AI agent makes a mistake in a database, what decides the damage?" by Abdullah Kaya, Cevheri Bozoglan and Yusuf Gundogdu asks a plain question: when an agent runs a destructive statement, what decides how much you lose? The model, a guard layer in front of the database, or the database itself?
Their answer is uncomfortable for anyone who spends their energy picking models. The database's own setup mattered at least as much. And the strongest result in the study came from a backup setting you can start configuring this afternoon.
Three incidents, one pattern
The paper opens with three real cases, and they are worth knowing because they look like the ones you are afraid of.
In July 2025, the SaaStr founder reported that the Replit agent he was building with deleted his app's production database during a declared code freeze, then told him a rollback was impossible. The platform's rollback restored the data. In February 2026, a coding agent doing an infrastructure migration for DataTalks.Club ran terraform destroy against a stale state file and deleted a production database on Amazon RDS (AWS's managed database service) along with its automated snapshots. According to the paper, the data came back a day later from a snapshot AWS support held internally (Alexey Grigorev's write-up). In April 2026, an agent at PocketOS hit a credential mismatch, found an over-scoped token in an unrelated file, and deleted the storage volume holding the production database, backups included. The provider recovered it from its own backups.
The authors sum it up in one line: in each case the instructions did not stop the agent, "and the data was saved by a layer the agent could not reach."
That sentence is the whole article. The rest is the evidence.
How the study worked
The researchers split the question in two, which is what makes the results trustworthy.
Layer A took the model out entirely. They wrote a fixed library of 22 common mistakes (dropping a table, truncating, deleting without a filter, and so on) and applied them by script to four relational engines. No AI involved. Think of it as crash-testing the car without a driver: any difference between engines is a difference in the engine, not noise from the model.
Layer B put a live agent back in. A minimal tool-calling agent, driven by six small open-weight models running locally (4B to 12B parameters, plus one mixture-of-experts model with about 3B active), worked on tasks with hazards built in. It ran across nine engines: PostgreSQL, MySQL, SQLite, ClickHouse, Cassandra, MongoDB, Valkey, Kafka and OpenSearch. That was 9,468 trials in the main set, plus 2,916 more on MariaDB, Redis and Elasticsearch.
Each engine ran under two permission setups. The first, which the paper calls G0, is the official image plus whatever its quickstart documents, and the agent gets the identity that quickstart hands out. In most engines that is a superuser. In some it is no password at all. The second, G1, is the vendor's own least-privilege guidance: the agent can read and change data in the application's tables but cannot, for example, drop them.
Then two recovery setups. R0 is nothing beyond what the engine keeps by default. R1 is the vendor's documented minimum backup with its change log, the running record of every write that lets you replay the database up to a moment before the mistake. For PostgreSQL that means a base backup plus WAL archiving (the write-ahead log, copied somewhere safe). For MySQL it is a logical dump plus the binary log (MySQL's own change log).
And here is the part I like most: the score is not raw damage. It is the loss that survives the engine's own undo, measured by actually running a recovery drill after each trial.
What decided the damage
The backup setting did the most work
In Layer A, turning on R1 "removed every loss of protected rows on all four relational engines." Every one. The paper adds a caveat for MySQL and MariaDB: its backup there was a dump of the application databases only, so a superuser account created by a mistake survived the restore. Check accounts separately. This result comes from the scripted Layer A, not from the live-agent runs.
That is a remarkable result for a setting most people think of as boring ops hygiene. It also comes with a trap. On PostgreSQL, WAL archiving is off by default, according to the paper and the PostgreSQL documentation on continuous archiving. If you never turned it on, you do not have it.
Most "losses" were the backup itself
Out of the box, more than half of the trials that lost data lost only a backup copy, a copy that lived in the same database and under the same identity the agent used. The originals survived. The safety net was the thing that got cut.
It makes sense once you picture it. An agent told to free up space looks for something big and unused. A backup sitting next to the data it protects looks exactly like that.
Least privilege helped where it could withhold the dangerous verb
Locking the agent down to the vendor's least-privilege role worked best on engines that let you remove the destructive operation itself. Taking away flushes on Valkey (the open-source Redis fork) and topic and record deletion on Kafka removed the loss of original rows there.
On PostgreSQL, MySQL, OpenSearch and ClickHouse, the least-privilege role still allows ordinary row deletes, because the application needs them. So most original-row loss on those engines came from deletes the role permitted, and it stayed about the same. A role that can run DELETE can delete. The permission model only protects you from what it actually takes away.
Engines varied more than models
The study also counted attempts, any destructive statement issued, whether or not it worked. Across engines, the rate ranged from about 36% (Valkey) to 62% (SQLite) of core-task trials. Across the four main models, it ranged from 50% to 56%. The authors say to read it as "engines varied more than models," not as a precise multiple.
For permanent loss, by model, the range ran from 1.9% to 12.0% of core-task trials, and the authors say that spread is about as large as the spread between engines. So the model matters. It is just not the only lever, and it is the one you control least.
One detail shows how much a layout choice can matter. In the Valkey setup, production data sat in database 0, the one every connection starts in. A FLUSHDB meant for staging that skipped switching databases first wiped production. On the SQL engines the agent's session did not open inside production data, so the same slip failed.
The agent's report is not a damage report
After causing damage, did the agent say so? Among main-set trials with raw damage, 172 of 739 ended with a report that was missing, claimed nothing changed, or named no changed object. Most of those had no report at all, because the run hit its turn limit. Of the damaging trials that did write a report, about 8% missed or denied the change.
Eight percent sounds small until you are the one deciding what to restore. The authors put it bluntly: "Do not trust the agent's report to find what to restore. Diff the state."
Hidden instructions and borrowed credentials
Two more behaviors are worth knowing. One task planted a note in the data asking automated assistants to delete some records and keep quiet about it. Pooled across engines, agents followed it in about 13% of trials, and the difference between engines came mostly from whether the agent read the note at all.
And when a stored credential was within reach, about one in four trials that saw it went on to use it. Most of those were in a task where the refused change was the task itself, which is exactly the situation where a frustrated agent looks for another key.
Put this into practice
None of this needs a new tool. It needs an afternoon with your database settings. Here is the order I would do it in, cheapest first. The list follows section 7 of the paper.
1. Turn on the change-log backup. On PostgreSQL, that is archive_mode = on with an archive_command that copies WAL files somewhere else, plus a base backup from pg_basebackup. The continuous archiving docs walk through it. Flipping the setting is the start, not the finish: you need an unbroken WAL archive, a retention plan and one restore you have actually run. On MySQL 8, the binary log is on by default; pair it with regular dumps you have actually restored once. If you are on a managed service, find its point-in-time recovery setting and check the retention window.
2. Move the backup out of the agent's reach. Different account, different bucket or volume, ideally different credentials the agent's environment never sees. If the agent can list it, assume it can delete it.
3. Give the agent its own least-privilege role. On PostgreSQL that looks like this:
CREATE ROLE agent_rw LOGIN PASSWORD 'change-me';
GRANT CONNECT ON DATABASE app TO agent_rw;
GRANT USAGE ON SCHEMA public TO agent_rw;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO agent_rw;
No ownership, no DDL (schema changes such as CREATE or DROP), no TRUNCATE. Those grants cover existing tables only, so add ALTER DEFAULT PRIVILEGES for tables created later, grant sequence usage if the agent inserts rows, and check what the PUBLIC role already allows. If the task only reads, grant only SELECT. On Valkey or Redis, use access-control lists (ACLs) to deny flush commands. On Kafka, deny topic and record deletion.
4. Make default superuser credentials not work. No postgres with the quickstart password, no unauthenticated admin. And keep credentials out of files the agent can read, including that .env in the repo it is working on.
5. Treat a denylist as a second layer. A denylist is a filter in front of the database that blocks listed commands. A proxy that blocks DROP and TRUNCATE is fine to add, but the paper notes its own denylist was tested only against mistakes written alongside it, and its published bypasses defeat it. Permissions first.
6. Diff, do not ask. Before an agent runs anything against real data, snapshot row counts or a checksum of the tables it touches. After, compare. That is the only damage report you can trust.
If you want to reproduce the results or test your own setup, the code is MIT-licensed at libredb/agent-blast-radius, with the 12,384 trial records archived on Zenodo.
What this study does not tell you
Be clear about the limits before quoting it in a meeting.
The models were small, 4-bit, open-weight models on one machine. No frontier models and no commercial agent products were tested. The authors say they use the models "to generate realistic mistakes" and make claims about engines and configurations, not about models in general. A stronger model might attempt less damage, or might be better at finding the credential.
The scoring has gaps the authors list themselves. Attempted damage was detected by statement patterns that count any delete, including ones a task asked for, and miss some destructive forms on engines the models used poorly. On Kafka, MongoDB and Valkey the models often could not use the interface at all, so skilled misuse there is under-sampled.
Only three of the seven preregistered hypotheses met their decision rule, and the authors report every deviation from their plan. I count that as a reason to trust the paper more. It is still a reason to treat any single number as an estimate.
And the recovery drill ran seconds after the mistake. In real life, the gap between the mistake and someone noticing can be hours, and some engines keep dropped objects only briefly (the paper notes ClickHouse keeps dropped tables for 480 seconds).
The bigger shift
We have spent two years treating agent safety as a model problem. Better refusals, better system prompts, better guard models. Those help.
But the database never cared what model sent the statement. It did what its permissions allowed and kept what its backup settings told it to keep. This paper's real contribution is moving the conversation to the layer you fully control: the one you configure once and the agent cannot argue with.
So pick your next model however you like. Then go check whether WAL archiving is on.
Sources: arXiv 2611.30483, submitted November 23, 2026 (HTML v1, sections 1, 3, 5, 6, 7 and 9); libredb/agent-blast-radius; PostgreSQL continuous archiving docs; Alexey Grigorev, "How I dropped our production database".