How you might know
- Tables, rows or columns missing, emptied or duplicated.
- Schema changes or migrations you did not ask for.
- An agent looping, retrying, or "fixing" its own mistakes with more commands.
- Counts that drop, or an app that suddenly shows empty pages, while the agent says all is well.
- (If the activity comes from outside, such as a flood of requests from unknown addresses, switch to the exposed-database playbook instead.)
Do this now
Stop the agent. All of it.
End the session and also any background tasks, schedulers, automations or CI jobs that can run it. Agents can keep working after you close the chat.
Take its keys, not just its plug
Cancel and replace every database login and key the agent used, including any it made for itself. If you cannot tell which, replace the database password or main key and update your real app. This makes "stop" stick.
Freeze the patient
Put your app in maintenance mode, or make the database read-only (remove write permission from the app's role). New writes into a half-broken database make recovery harder.
Do not ask the agent to fix it
It cannot see the full damage, and an agent that panics can pile fix on fix. No more commands from it, and no "quick checks" that write anything.
Snapshot the damaged state first
Take a dump or snapshot of the database as it is now. It is evidence, and it is your safety net if the restore goes wrong.
Find the last good moment
Look at your backups and, if you have it, "point-in-time recovery" (a rewind button for databases; on some services it costs extra). Use the AI's record of what it did to find the first bad command, then restore to a moment just before it.
Restore into a NEW database, then compare
On Supabase, restoring to an earlier point replaces the current state, and its docs advise restoring to a new project first. Check row counts of key tables against what you expect, work out what customers added after the restore point, and only then switch your app over.
Check the rest of the blast radius
Look beyond the database: files, changes it made live, messages it sent, other services it was connected to. Read the full record of its actions. Look at what it read before it went wrong, because hidden instructions in an email or web page can steer an AI.
Tell the right people
Tell your team and, if customer data was lost or exposed, your customers, plainly and without guessing.
Do not do this
- Do not let the agent repair its own mess on live data.
- Do not overwrite your damaged database with a restore until you have snapshotted it.
- Do not trust the agent's own summary as the only record.
- Do not delete logs, transcripts or migration history.
- Do not panic-run your own fix commands without a plan. A calm five minutes beats a fast wrong command.
Who to tell
- Whoever owns the database and the app
- Whoever is in charge
- Customers, if their data was lost or exposed
What to save before you clean up
- The agent's transcript and tool-call log
- Database logs and migration history
- The snapshot of the damaged state
- Timestamps of the first bad action and each step you took
In the next 24 hours
- Give agents a copy of the data (or a staging database), never the live one.
- Use separate keys for the live system and for practice, and make the AI look-only by default.
- Require a human approval for destructive SQL: DROP, TRUNCATE, deleting without a WHERE, and schema migrations.
- Turn on backups, test a restore on a copy, and add alerts for sudden row-count or schema changes.
Official help for the platforms involved
Links open each provider's own documentation, so you do not have to search for it.
What to write in the post mortem afterwards
- What access the agent had versus what it needed
- Which actions should have needed approval
- How long recovery took and why
- Which guardrail makes this impossible next time, not just unlikely
References
- Supabase docs: Database backups and point-in-time recoverySupabase Docs
- Fortune: Replit agent deleted a live database during a code freezeFortune, Jul 23, 2025
- OWASP Top 10 for LLM applications (includes excessive agency)OWASP GenAI Security Project
Finished this one?
Add it to What I learned and earn 30 Trust. You can open your list from the badge at the bottom of the page.