Sub topic 14
Handling incidents and exceptions
This chapter assumes you know the basic pull request workflow, have used a code review process, and have seen a CI pipeline. It also assumes your team already has an AI-assisted code policy, covering acceptable use, data rules, accountability, and guardrails. No policy covers every case. This chapter covers what to do when something goes wrong and how to handle a justified request to break a rule.
Two different situations
An incident is an event where the policy was broken or a policy gap caused harm. Examples: a developer pasted a customer database export into a chat tool, an agent ran a destructive command, or AI-generated code with a security flaw reached production.
An exception is a planned, approved departure from a rule. Example: a team wants to use an unapproved tool for a two-week prototype that touches no restricted code.
Both need a written process. Without one, people hide mistakes or quietly bypass rules.
Incident response
Keep the process short enough that people actually follow it. Most teams reuse their existing security incident process and add AI-specific steps.
- Report. Tell the named contact (for example the security channel) as soon as you notice. Make reporting easy and free of punishment for honest mistakes.
- Contain. Stop further harm. Revoke exposed credentials, disable the agent's access, or revert the merge.
- Assess. Decide what was shared or changed, with which tool, and under what vendor terms. Check whether the vendor retains or trains on submitted data.
- Fix and recover. Rotate secrets, patch the code, notify affected parties if required by contract or law.
- Review. Hold a blameless review. Ask why the system allowed the mistake, not who made it.
- Update. Change the policy, training, or guardrails so the same failure is harder to repeat.
A leaked secret is the most common case. Treat any secret sent to an external tool as compromised and rotate it, even if the vendor says it does not retain prompts.
Handling exceptions
An exception process lets people request a deviation without ignoring the rule. A good request records:
- The rule being waived and the reason.
- The scope: which repository, tool, or data.
- The risk and any compensating controls, such as using synthetic data.
- An approver, such as a security lead or engineering manager.
- An expiry date.
Store requests in a visible place, such as a repository folder or ticket queue, so approvals are auditable.
# Exception request: AI-EXC-014
- Rule waived: Only approved tools may be used
- Requester: [email protected]
- Scope: `prototype-ui` repository only, no customer data
- Compensating controls: synthetic data, no secrets in prompts
- Approver: @example-org/security-team
- Expires: 2026-12-31Expiry matters. Without it, exceptions become permanent and the rule erodes. Review open exceptions on a schedule. If the same exception is requested repeatedly, the rule probably needs revising.
Common mistakes
- No clear reporter path. People do not know whom to tell, so reports come late.
- Blame-first reviews. Developers learn to hide incidents.
- Informal exceptions. A verbal "fine, go ahead" leaves no record and no expiry.
- Fixing only the symptom. Rotating a key helps, but if nothing changes, the leak recurs.
Exercise
A developer pasted an API key into an AI chat tool while debugging, then told no one for two days. List the first two actions the team should take, and one process change to reduce delay in future reports.
Show answer
First, treat the key as compromised and rotate it, then assess what else was shared and under which vendor terms. To reduce delay, make reporting easy and blameless, for example with a named channel and a statement that honest reports are not punished. Add a blameless review to find why the developer hesitated.
Exercise
Why should every approved exception have an expiry date?
Show answer
Without an expiry, a temporary deviation becomes a permanent one, and the rule loses force. An expiry forces a re-review of whether the exception is still needed and whether the rule itself should change.