Sub topic 14
Handling incidents and exceptions
This chapter covers what a team does when the AI-assisted code policy is broken, when a tool causes harm, and when someone has a good reason to step outside the rules. It assumes you have read the earlier chapters on acceptable use, data confidentiality, accountability, and automated guardrails. It also assumes you know the basic Git and pull request workflow, and that you know what a CI pipeline is.
A policy that only describes the normal case is incomplete. Sooner or later someone pastes a secret into a chat tool, an agent edits files it should not touch, or a deadline makes a team want to bend a rule. The team needs a plan for these moments before they happen.
Incidents and exceptions are different things
An incident is something that went wrong. A violation, a leak, or a harmful change has already happened or may be in progress. The goal is to contain the damage and learn from it.
An exception is a planned, approved departure from the policy. Nothing has gone wrong yet. Someone asks for permission to do something the policy would otherwise block.
Teams that mix these up end up punishing people who ask for exceptions, or quietly treating incidents as exceptions after the fact. Keep two separate paths.
| Aspect | Incident | Exception |
|---|---|---|
| Timing | After something went wrong | Before the action |
| Trigger | Leak, violation, harmful change | A need the policy blocks |
| First goal | Contain the damage | Decide whether the risk is acceptable |
| Who decides | Incident lead, with security | Named approver |
| Output | Fix, report, policy change | Written approval with an expiry date |
What counts as an AI-related incident
Define the categories in the policy so people know when to raise a hand. Common ones follow.
- Data exposure. Secrets, credentials, customer data, or restricted source code were sent to a tool that is not approved for them.
- Unapproved tool use. Someone used a tool that has not passed the approval process, even if no data was visibly harmed.
- Harmful agent action. An agentic tool ran a destructive command, changed files outside its scope, or pushed or deployed something it should not have.
- Defective change in production. An AI-assisted change caused an outage, a security hole, or data loss.
- Licensing concern. Generated code appears to copy licensed material that the project cannot use.
- Bypassed controls. Someone disabled a required check or merged around branch protection.
Notice that the list includes near misses. A secret that was caught before it left the laptop is still worth reporting, because it shows a gap in the controls.
Make reporting safe and easy
The most important design choice is cultural. If reporting an incident gets someone punished, people will hide incidents. Your policy should state that prompt, honest reports are treated as help, and that the response focuses on fixing the system rather than blaming the person.
This does not remove accountability. The author still owns the change, as the accountability chapter explains. But owning a change means fixing it and reporting it quickly, not concealing it. Reserve disciplinary action for concealment, repeated willful violations, and deliberate bypassing of controls.
Make the channel obvious. A single named place, such as a security mailbox or a dedicated chat channel, works better than a list of options. Put the link in the pull request template and in the policy itself.
A response workflow
A simple response follows five steps. Keep it short enough that someone can follow it while stressed.
- Report. The person who notices tells the named channel. They do not wait to understand everything.
- Contain. Stop further damage. Revoke or rotate exposed credentials, disable the agent's access, revert or freeze the change, or turn off the tool for the team.
- Assess. Work out what was exposed or changed, for how long, and who could see it.
- Notify. Inform affected people. Depending on the data, this may include customers, legal staff, or regulators. The policy should name who decides this.
- Learn. Hold a blameless review, record what happened, and change the policy, tools, or checks to prevent a repeat.
Containment comes before investigation. The urgent action for a leaked secret is rotation. Assume that anything sent to an external service may be stored, so deleting the chat history does not undo the exposure.
Example: a leaked API key
A developer pastes a config file into an AI chat to debug an error. Later they notice it contained a live API key.
- They report it to the security channel within minutes.
- The security team rotates the key and checks access logs for use of the old one.
- They check whether the tool's data settings allow the provider to retain the prompt, and they ask the vendor to delete it if the contract permits.
- In the review, the team finds that no secret scanner runs on local files. They add a pre-commit scanner and a note in the policy about redacting config files before sharing.
The outcome is a fixed system, and the developer is not blamed for reporting.
Using guardrails to detect incidents
Automated checks from the earlier chapter catch many incidents early. A required CI job, such as the test job below, blocks merges when tests fail, and branch protection stops anyone from skipping it.
# .github/workflows/ci.yml
name: ci
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm testA CODEOWNERS file also helps with response. It tells you who owns a sensitive path, so during an incident you know whom to call.
# .github/CODEOWNERS
/auth/ @example-org/security-team
/payments/ @example-org/payments-team
/.github/ @example-org/platform-team
/docs/policies/ @example-org/engineering-leadsAudit logs matter too. Repository settings changes, force pushes, and disabled checks should be logged and reviewed, so a bypass is visible rather than silent.
Handling exceptions
Strict rules will sometimes fit badly. A team may need to use a tool with restricted code in an isolated environment, or let an agent run with broader permissions for a one-off migration. If there is no legitimate way to ask, people will work around the rule without telling anyone.
A good exception process has these parts.
- A written request. It states what is needed, why, and which rule it affects.
- A risk assessment. It names what could go wrong and what limits will reduce that risk.
- A named approver. The policy says who can approve which kind of exception. For example, a team lead may approve low-risk ones, while security must approve anything involving customer data.
- Conditions. Examples are a sandboxed environment, extra review, or logging.
- An expiry date. An exception with no end becomes a permanent hole in the policy.
- A record. Keep exceptions in one searchable place.
Example: an exception record
## Exception 2026-014
- **Rule affected:** Restricted code may not be sent to external AI tools
- **Requested by:** Priya N., payments team
- **Reason:** One-time migration of a legacy module with no documentation
- **Approver:** Security lead
- **Conditions:** Use the approved enterprise tool only; no customer data in prompts; a second reviewer on every pull request
- **Expires:** 2026-12-31
- **Review:** Reassess at expiry; close if migration is completeWatch the pattern of requests. If the same exception is requested again and again, the rule may be wrong. Treat that as input to the policy revision process rather than approving the same thing forever.
Common mistakes
- No owner for incidents. When everyone is responsible, nobody acts. Name an incident lead role and a backup.
- Treating the tool as the cause. Banning a tool after one incident can push usage to unapproved tools. Ask what control was missing.
- Skipping the review step. Teams fix the immediate problem and move on, so the same incident returns.
- Verbal exceptions. An exception granted in a hallway cannot be audited or expired.
- Deleting evidence. Do not wipe logs or histories before the assessment is done.
- Never testing the process. Run a short tabletop drill once or twice a year. Walk through a made-up leak and see whether people know whom to contact.
Feeding lessons back
Each incident and each exception is data. After a review, record the cause and the change you made, such as a new CI check, a tightened agent permission, or a clarified rule. The final chapter on measuring the policy covers counting these events over time. For now, the principle is that every incident should leave the team with at least one improved control.
Exercise
A developer asks to let an AI agent run with broad file-write and shell access for a one-week data migration, though the policy limits agents to read-only access by default. Is this an incident or an exception, and what should the written approval include?
Show answer
It is an exception, because it is a request made before acting and nothing has gone wrong. The approval should state the rule affected, the reason, a risk assessment, a named approver, conditions (for example a sandboxed environment, logging, and extra review of the agent's changes), an expiry date at the end of the week, and a place in the shared exception record.
Exercise
You discover that a teammate pasted a production database connection string into an unapproved chat tool yesterday. List the first two actions in order and explain why that order is correct.
Show answer
First, report to the named incident channel and rotate the connection string (contain). Second, assess scope, such as checking database access logs for use of the old credentials and finding out what the tool retains. Containment comes first because the exposed credential may already be misused, and investigation can continue after the risk is cut off.