# How to stop an AI agent from deleting production data

Source: https://osevel.com/learn/stop-ai-agent-deleting-data/ · reviewed 2026-11-28

> Do not rely on the agent being careful; take the power away where it matters. Give it a login that cannot drop or truncate tables, hold deletes without a filter and large deletes for a person, keep every deleted row so it can be put back, and count what a delete would remove before it runs.

## How an agent ends up deleting data

- A DELETE or UPDATE without a WHERE clause.
- A WHERE clause that matches far more rows than meant, from a wrong date or a typo.
- A “cleanup” that drops or truncates a table.
- Foreign keys that cascade a small delete into thousands of rows.
- An instruction hidden in the data it read, written to make a model act.

## Four layers that stop it

- A login without destructive rights: the agent’s role cannot drop, truncate or alter tables.
- Rules that ask a person: deletes without a filter, and writes above a row count, wait for approval.
- A count before it runs: a trial run, rolled back, says how many rows a delete would remove, cascades included.
- A record of every row: each deleted row is kept, so it can be inserted back without a restore.

## What OsBase does

- The agent’s role cannot change the schema; DROP and TRUNCATE need an approved request.
- By default UPDATE or DELETE without WHERE, and writes over 100 rows, wait for a person; so do more than 1,000 rows per session in 10 minutes.
- The approval shows how many rows the statement would remove, counted in a trial run.
- Undo inserts deleted rows back, for one change or a whole agent session.

## Questions

### Is a backup not enough?

A backup brings back everything as it was at one moment, including undoing everyone else’s work since. Putting back only the rows the agent removed is faster and loses nothing else.

### What about TRUNCATE and DROP?

With OsBase they are schema changes: they always need approval, and where it can, the approval shows how many rows they would destroy.
