Chapter 31
31 / 50

Debugging & Incident Playbook

⏱️ 35 min

Debugging & Incident Playbook

When an LLM system breaks, the scariest part isn't the error itself -- it's the team not knowing where to look first. AI incidents are rarely single-point failures. They can involve the model, retrieval, prompt, tools, provider, queue -- or sometimes just a config change that quietly amplified bad behavior. Without a playbook, debugging feels like stumbling around in the dark.

So this page isn't about "check logs when things break." It's about how AI engineers should turn debugging and incident response into a reusable production workflow.

AI Incident Response Flow


Bottom line: classify first, then debug

The most common mistake during AI incidents is immediately staring at model output.

A more effective sequence:

  1. Identify what type of incident this is
  2. Narrow down to which layer
  3. Only then do prompt / model-level investigation

If you don't classify first, debugging gets buried in noise.


5 common types of AI incidents

TypeCommon symptoms
provider / infra401, 403, 429, 5xx, timeout
quality driftSuddenly more hallucinations, bad citations, broken formatting
retrieval failureCan't find sources, citations are empty
tool failureTool timeout, schema mismatch, execution error
cost / latency spikeToken usage spikes, excessive fallbacks, P95 blows up

Classify the incident into one of these categories and you'll locate the problem much faster.


What to check in the first round of triage

A more practical triage order:

QuestionWhere to look first
Was there a recent config / prompt / model change?deploy / config timeline
Is the error concentrated on one provider / region?provider dashboard / route log
Is everything broken, or just a specific request type?request segment / tenant / feature flag
Is it a deterministic error or quality drift?logs + samples + metrics

The worst thing during an AI incident is fixating on a single bad sample. Look at the big picture first, then zoom in.


A more production-like debugging layer model

LayerWhat to investigate
request layerWhich users, which feature, which tenant is affected
routing layerWhich provider / model / fallback was used
context layerIs the prompt, history, or retrieval chunk abnormal?
execution layerAre tools, queues, workers, timeout, or retries failing?
outcome layerAre quality, cost, latency, or schema out of control?

With these layers, incident discussions become much more productive than "did the model get dumber?"


Quick actions for common incidents

IncidentFaster action
401 / 403Check key, permissions, env changes first
429Reduce concurrency, enable backoff, check traffic spike
5xx / timeoutCheck provider health, switch to fallback if needed
schema failAdd a repair path or revert to old prompt
hallucination surgeLower temperature, tighten scope, strengthen source guard

In incident response, "stop the bleeding first" is usually more important than "find the root cause immediately."


Tracing and logging: what's the minimum?

Debugging AI without a trace ID is almost always painful later.

Each request should at minimum be linked to:

  • trace_id
  • model / provider
  • prompt or config version
  • retry count
  • retrieval source IDs
  • tool call summary
  • latency
  • token usage

This isn't about logging sensitive content verbatim -- it's about being able to trace a bad request end-to-end through the system.


Quality incidents and infra incidents aren't the same thing

This is where many teams get confused.

Infra incidentQuality incident
Obvious errors, timeouts, failuresLooks successful, but content is noticeably worse
Easier to detect with system metricsOften only found through sample review
Usually look at provider / worker firstUsually look at prompt / retrieval / policy first

If you treat a quality incident like a regular 5xx outage, you'll miss the real problem.


Runbooks shouldn't just be archived docs

A usable runbook needs at minimum:

  1. Symptoms
  2. Quick diagnostic entry points
  3. Temporary mitigation actions
  4. Root cause investigation path
  5. Rollback method
  6. Responsible person and escalation path

Without these, runbooks quickly become "postmortem reading material" instead of a tool you actually use on-call.


The most valuable part of a postmortem

AI incident postmortems shouldn't just say "issue fixed."

What they should really cover:

  • Which monitor should have alerted earlier?
  • Which bad case should be added to the eval set?
  • Which rollback switch wasn't fast enough?
  • Which guardrail could have caught it proactively?

A truly good postmortem turns incidents into future system capabilities.


Practice

Take one of your live AI features and fill in these 4 things:

  1. A one-page incident classification table
  2. A one-page triage sequence
  3. Runbooks for your 3 most common failure types
  4. A set of fields that must be in every trace

Once these are in place, the team will be much more stable when things go wrong.

📚 Related resources

Common questions

Open a question to review the practical answer.

What is the correct order for AI incident triage?

Classify first, layer second, model last. Three steps: (1) identify the incident type — provider/infra, quality drift, retrieval failure, tool failure, or cost/latency spike; (2) narrow to a layer — request / routing / context / execution / outcome; (3) only then dive into prompt or model. Starting from a single bad sample drowns you in noise.

What should the first-round triage check?

Four questions, broad to narrow: any recent config / prompt / model change (check the deploy timeline), are errors concentrated in one provider or region (check provider dashboards), is it global or scoped to a segment / tenant / feature flag, and is it a deterministic error or quality drift. Start with the broad view — drilling into individual cases first wastes time.

How do quality incidents differ from infra incidents in response?

Two different playbooks. Infra incident: visible errors, timeouts, failures — caught by system metrics, start with provider and worker. Quality incident: looks successful but content is noticeably worse — caught by sample review, start with prompt / retrieval / policy. Treating a quality incident like a 5xx is a common misdiagnosis — you keep tuning retries when retries are not the problem.

Which fields must each AI request trace to make debugging tractable?

At least eight fields: trace_id, model/provider, prompt or config version, retry count, retrieval source IDs, tool call summary, latency, and token usage. Not full sensitive content — just enough to reassemble one bad request across the system. Debugging without a trace_id is almost always painful.

What does a runbook need to actually be useful during an incident?

Six pieces, all required: symptoms, quick diagnostic entry points, immediate mitigation actions, root-cause path, rollback procedure, owner and escalation path. The three most common failure modes each need their own runbook: 401/403 — check keys and permissions first; 429 — drop concurrency and add backoff; hallucination surge — lower temperature, narrow scope, add source guards. A runbook that is only opened after the fact is dead weight.