AI Agents and Coding Assistants

How to Audit What an AI Agent Did and Undo Its Mistakes

How to reconstruct an AI agent's actions from independent records, contain the damage, reverse what you can and prevent a repeat.

Key takeaways

  • Stop the agent and cut its access before you start investigating or repairing anything.
  • The agent's own summary is a lead to check, not proof of what happened.
  • System records such as version histories, sent mail and transaction statements are the stronger evidence.
  • Some actions, including sent messages and exposed data, cannot be reversed and need follow-up with people.
  • Backups, version history and a separate agent identity must be set up before the problem occurs.

To audit an agent, rebuild what it actually did from records it did not write: file histories, sent folders, account logs and payment statements. To undo its mistakes, stop it first, list every change, reverse the ones you can and deal directly with the ones you cannot.

Both jobs are far easier if you prepared beforehand. An agent working in a place with version history and clear logs leaves a trail you can follow. One working with your full login and permanent delete rights may leave very little.

Stop first, then look

A running agent can keep making changes while you read. It may also try to fix the problem on its own and overwrite the evidence.

Pause or end the task. Revoke the agent's access tokens or sign it out. Check for scheduled jobs, queued messages and automations it may have created, since these can continue after the main session closes. Then resist the urge to ask it to "put everything back." A repair attempt by the same system, under the same misunderstanding, can compound the damage.

If money, security or other people's data is involved, tell the responsible person right away. Early notice gives banks, administrators and affected people more room to act.

Gather the records

Collect evidence from several places and save copies, because some logs are kept only for a limited time.

Source What it can show Limitation
Agent transcript Instructions, reasoning shown, tools it called May be incomplete or summarized
Tool or connector log Each request and the response Not offered by every product
File version history What changed and when Retention periods vary
Sent mail and shared links What left your control Deleted items may eventually vanish
Account activity log Sign-ins, setting and permission changes Some detail only for administrators
Bank or card statement Charges and transfers Pending items can lag

Save the original instruction exactly as given, along with any documents or pages the agent read near the point where things went wrong.

Treat the agent's account with care

You can ask an agent what it did, and the answer may be a useful map. It is still generated text. A model may leave out a step, describe an action it only planned, or offer a tidy explanation of why it acted that has little to do with the actual cause.

This is a form of the broader habit in which models state wrong things smoothly. Check each claimed action against a system record. Also search the records for actions the account never mentions, which matter most.

Build a timeline

Put every action in order with its time, target and result. Mark each one as expected, wrong or unclear. Then find the first wrong step, because later errors often follow from it.

Ask what the agent saw just before that step. Common causes include an ambiguous instruction, a file with a misleading name, outdated information, a tool that failed silently and returned something odd, or planted text such as in a prompt injection attack. The answer shapes the fix.

Remember that small slips build on one another over long tasks, a pattern examined in why errors compound across many steps. Work forward from the first fault and assume downstream results are suspect until checked.

Reverse what can be reversed

Recovering from an agent's mistake
1 Contain Stop the agent and revoke its access 2 Preserve Save logs, transcripts and copies 3 List changes Check each against system records 4 Reverse Restore, cancel, correct or refund 5 Notify Tell people about what cannot be undone 6 Prevent Change permissions, checks and instructions Contain Stop the agent and revoke its access 1 Preserve Save logs, transcripts and copies 2 List changes Check each against system records 3 Reverse Restore, cancel, correct or refund 4 Notify Tell people about what cannot be undone 5 Prevent Change permissions, checks and instructions 6

Different mistakes call for different tools.

  • Edited files: restore an earlier version. Check whether people made good changes since, so you do not wipe them out.
  • Deleted items: look in the trash or recycle folder soon, then in backups.
  • Changed settings: return them to known values and look for new rules, users or forwarding addresses.
  • Database records: ask whoever runs the system. A full restore can erase newer legitimate entries, so targeted correction is often better.
  • Orders and bookings: cancel quickly and note the confirmation number.
  • Payments: contact the bank or payment service at once, since some transfers can be stopped only for a short time.

Keep your own log of repairs. After restoring, verify the result instead of trusting a success message.

A worked reconstruction

Say you asked an agent to tidy a shared project folder, and a colleague reports that last month's budget file is gone. You stop the agent and remove its access to the folder.

The agent's summary says it "archived outdated files." The folder's activity history is more specific. It shows several files moved to an archive subfolder and two sent to the trash. One of the two is the budget. The history also shows a rename that the summary never mentioned.

You build the timeline and find the first wrong step: the agent treated two files with similar names as duplicates and removed the one with the earlier date. In fact that one held the approved figures, and the newer file was an unfinished copy.

Recovery is straightforward here. You restore the budget from the trash, reverse the rename and compare the archive list with your colleagues to catch anything else in use. Then you tell everyone who might have opened the draft that week, in case they copied numbers from it.

The lasting fix is not a sterner sentence about duplicates. You remove permission to delete, require the agent to propose a list of moves for approval and have it compare file contents before calling anything a duplicate.

Check the repair for side effects

Restoring one thing can disturb another. A restored file may overwrite later edits. A canceled order may also cancel items you wanted. Reversing a calendar change may send a fresh round of notices to dozens of people.

Before each repair, ask what else it will touch. After it, confirm the result in the system itself and have someone who knows the material look. Watch for delayed effects over the next few days: synced devices that bring back old copies, automations triggered by the restore, or reports built from the faulty data that have already been shared.

Close the review with a short written note covering what happened, what was fixed, what could not be fixed and what changed as a result. Keep it factual and free of blame, so that people will report the next problem early.

Handle what cannot be undone

A sent email has been read or might be. Published information may have been copied. A leaked password must be considered known.

For messages, send a short, factual correction: what was wrong, what is right and what the recipient should disregard or delete. Do not blame the tool in a way that suggests you have no responsibility for it. For exposed credentials, replace them and end existing sessions. For exposed personal data, there may be legal duties to report within a set time, so involve your privacy or legal contact early.

Find the cause and prevent a repeat

Ask why the mistake was possible, not only why the agent chose it. Useful questions include:

  1. Did it need the permission that allowed the damage?
  2. Should this action have required approval?
  3. Was the instruction missing a boundary or a stop condition?
  4. Would a test run have exposed the problem?
  5. How long before anyone noticed, and what would shorten that?

Then change something concrete. Trim access using the least-access checklist, add an approval step or add an automatic check that compares results with expectations. Rewriting the instructions helps, though on its own it rarely guarantees anything.

Set up for easy audits

Preparation costs little compared with reconstruction.

  • Give the agent a separate identity so its actions are labeled.
  • Turn on version history and confirm how long it lasts.
  • Keep backups the agent cannot modify.
  • Prefer archiving to permanent deletion.
  • Ask the agent to keep a plain change list as it works, then spot-check it against system logs.
  • Before large jobs, take a snapshot, meaning a saved copy of the current state.
  • Practice one restore, so you know it works.

For logs that contain sensitive content, control who can read them and delete them on a sensible schedule. A record that helps an audit can also become a leak if left open.

Common questions

How often should I audit when nothing seems wrong?

Sample regularly. Early on, review every consequential action. Later, check a random selection each week, plus all unusual ones. Problems that produce no complaint are found only by looking.

What if the product keeps no useful log?

Rely on the records of the systems it touched, and consider that a limit on what you should let it do. Work you cannot reconstruct is hard to delegate responsibly.

Can I test recovery without risking real data?

Yes. Use a sandbox or test account, let the agent make changes, then try to find and reverse each of them. Gaps show up quickly and cheaply.

Written for 4ArtificialIntelligence with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 46 articles in AI Agents and Coding Assistants →

Latest news on this topic