CCDV-P Study Guide
Free study guide for the Claude Certified Developer - Professional (CCDV-P) exam: 25 lessons, one per official skill, on running Claude systems in production. One chapter per exam domain, one page per lesson, in the order the official exam guide lists them.
4. Domain 4: Advanced Debugging and Incident Response
4.1. 4.1 Complex failure diagnosis: finding where a multi-agent failure starts
CCDV-P · Domain 4 · Lesson 4.1 · 22 min read
Find where a multi-turn or multi-agent failure starts (model, harness, tools or data) with fixed-input replays, refusal handling and grounding checks.
Why the failure never shows where it starts
Strand & Kepler is a legal services firm that reviews commercial contracts for about 140 enterprise clients. Its contract-review pipeline handles roughly 2,400 contracts a month. A drafting agent reads the counterparty's paper, pulls the client's negotiation playbook with a get_client_playbook tool, finds standard wording with search_clause_library, and produces a marked-up draft. A review agent then checks the draft and returns APPROVED or REJECTED. Approved drafts go to a lawyer for signature with a light read.
About 610 of those contracts a month belong to clients whose playbook makes a liability cap mandatory, usually twelve months of fees. A partner's spot audit found 41 of them approved without any cap last month: roughly one run in fifteen. Every API call returned HTTP 200. Every review ended with stop_reason: "end_turn". Latency and cost were normal. Nothing in the dashboards was red.
The tempting reading is "the review model is not good enough". That reading starts from where the failure SHOWS, the verdict. But the cap could have dropped out at four earlier points, each with a different owner and a different fix.
Where the liability cap can get lost
get_client_playbook returns itFour origins, and the evidence that points to each
Here is the question the exam keeps asking in different clothes: the output is wrong, so whose fault is it? Every failure in a Claude system starts in one of four places. Model output is the model reasoning badly over context that was correct. The harness is your orchestration code: how it assembles context, truncates or compacts history, passes work between agents, parses replies and branches on stop_reason. Tools are the functions and services the model calls. Data is what those tools and retrievers read: records, documents, indexes.
The method is to walk backward from the bad output and ask the same question at each hop: was the information needed for a correct answer present and correct here? The first hop where the answer is no is the origin. A plumber who finds a stain on the ceiling does not replace the ceiling. They follow the pipe upward until it is dry, and the leak sits just below the first dry joint.
| Origin | Evidence that points here | First check in the trace |
|---|---|---|
| Model output | The needed fact was in the model's context and the output contradicts or ignores it; failure rate varies across identical replays | Read the exact input of the failing model call, then replay it N times |
| Harness | The fact existed upstream but never reached the failing call; failures cluster by input length, prompt version, handoff format or stop condition | Diff the context the harness built against what the tools returned |
| Tools | A tool span shows an error, timeout, empty or stale result, or a result returned as success when it failed | Read tool span status and the tool_result content |
| Data | The tool worked and returned exactly what the source holds, but the source itself is wrong or incomplete | Compare the source record with the ground truth |
Memorise the shape of each row: model output means "it had it and misused it", harness means "it never got it", tools means "the call failed or lied", data means "the source was wrong". To read these hops at all you need per-step traces; the Agent SDK, for example, can export a span for each model request and each tool call, with subagent spans nested under the parent's tool span. Content capture there is opt-in, so check what your traces actually hold before you rely on them.
At Strand & Kepler the walk-back went quickly. In all 41 failures the playbook record held the cap and get_client_playbook returned it without error, which cleared the playbook data and the playbook tool. The cap requirement was in the drafting agent's context, so the question moved to what happened after that hop: the handoff between the two agents, the review call and the drafting itself.
Multi-turn and multi-agent failures: the constraint that got lost
Two kinds of failure hide their origin especially well, because the bad turn and the bad output are far apart. In a multi-turn failure, an early turn poisons a later one. A wrong tool result in turn 2 becomes a "fact" the agent builds on in turns 3 to 9; a compaction step drops an instruction the user gave at the start; a turn left in history keeps steering every turn after it. The final answer looks like a reasoning error, but the reasoning was sound given what the agent was carrying. Find the first turn whose working state contradicts the source, and fix that turn.
In a multi-agent failure, a handoff loses a constraint. A subagent's context starts fresh. In the Claude Agent SDK, for example, the only content the parent passes to a non-fork subagent is the prompt string of the Agent tool call, so anything the subagent must know has to be in that string. Anthropic's write-up of its multi-agent research system makes the same point from the other side: without detailed task descriptions, subagents duplicate work, leave gaps or miss information.
Strand & Kepler's trace for one failing contract shows the pattern. Look at the handoff line and at what the reviewer received.
trace 7f3a contract SK-22817 client C-0412 (playbook: liability cap = 12 months' fees)
drafting_agent turn 1 tool get_client_playbook -> ok, 14 terms incl. liability_cap
drafting_agent turn 5 output: draft v3 + handoff note (212 words, free text)
handoff note covers: governing law, payment terms, IP ownership [no liability cap]
review_agent input: handoff note + draft v3 (no playbook, no tools)
review_agent stop_reason end_turn verdict APPROVED
The review agent never saw the playbook. Its only knowledge of the client's mandatory terms was a summary the drafting agent wrote in its own words, and that summary mentioned the cap in some runs and not in others. In 31 of the 41 failures the note left the cap out.
What each agent had in context
Drafting agent
Review agent
its verdict depends on the note
So which origin is it? The note's variability is model behaviour, but the DESIGN that let a hard client requirement travel only through a model-written summary is the harness. The fix belongs at that boundary: the pipeline passes the playbook's mandatory terms to the reviewer as structured data straight from the source, and a code check refuses APPROVED when a mandatory term has no matching clause in the draft. Telling the reviewer "always check the liability cap" would not help; it cannot check a cap it was never told about.
Non-determinism: one run in fifteen is a distribution
The first engineer on the case reran contract SK-22817 once. The reviewer rejected it, correctly, and the ticket nearly closed as "transient". This is the trap of a non-deterministic failure: the same input does not give the same output every time, so a single rerun tells you almost nothing. If a failure happens one run in fifteen, even fifteen reruns show no failure at all about 36 percent of the time: 14/15 to the power of 15 is 0.355, roughly one in three.
It is tempting to reach for temperature 0 to make runs repeatable. Resist it. Anthropic's glossary states that even at temperature 0 results are not fully deterministic, and from API version 2026-10-21 the temperature, top_p and top_k parameters are removed altogether: sending them returns a 400 error. You cannot make the model deterministic, so you make everything AROUND it fixed and measure the model as a distribution.
That is a fixed-input replay. Take the failing trace and pin everything it recorded: the model id, the prompt version, and the exact tool results and handoff text, read back from the trace instead of from live tools. Then run the step N times and count outcomes. Here is a minimal replay of the review step. Look at the two pinned values at the top, the refusal branch, and the count over N identical runs.
import anthropic
api = anthropic.Anthropic()
MODEL = "claude-sonnet-5-5" # PIN the model id from the trace
REVIEW_PROMPT = open("review_prompt_v14.txt").read() # PIN the prompt version from the trace
def review(handoff: str, draft: str) -> str:
resp = api.messages.create(
model=MODEL, max_tokens=1500, system=REVIEW_PROMPT,
messages=[{"role": "user", "content": f"{handoff}\n\n<draft>\n{draft}\n</draft>"}],
)
if resp.stop_reason == "refusal": # a refusal is its own outcome
return "REFUSED"
text = "".join(b.text for b in resp.content if b.type == "text")
return "APPROVED" if "VERDICT: APPROVED" in text else "REJECTED"
def approval_rate(handoff: str, draft: str, n: int = 100) -> float:
verdicts = [review(handoff, draft) for _ in range(n)] # SAME inputs, n runs
return verdicts.count("APPROVED") / n
The power comes from changing one thing at a time. Strand & Kepler ran three replays of SK-22817, 100 runs each. With the recorded cap-less note held fixed, the reviewer approved 100 of 100. With a note that named the cap, it approved 0 of 100. Rerunning only the drafting agent, its note left the cap out 8 times in 100. That locates the variance exactly: the reviewer behaves consistently given its input, and the randomness lives in what the drafter chose to summarise.
Refusals: a failure class of their own
Ten of the 41 failures did not fit the handoff story: their notes named the cap. Five of them shared a second pattern. In each, the review call ended with stop_reason: "refusal" and no text, and the harness's parser, which looked for listed problems, found none and returned APPROVED. These were contracts for a security-testing client full of clauses about penetration testing, the kind of benign work Anthropic's documentation says can still trip a safety classifier.
A refusal is the model or its safety classifiers declining to produce a response, and it is a failure class of its own: not an error, not an empty success, not a reasoning mistake. It arrives as HTTP 200, so monitoring built on error rates never sees it, and a batch job reports a refused item as a succeeded result. It comes in three forms that need different handling.
| Form | What you see | What your code does |
|---|---|---|
| Classifier refusal | HTTP 200, stop_reason: "refusal", a stop_details object whose category and explanation may be null, possibly partial text |
Discard any partial output; do not resend unchanged to the same model; reset or rephrase the context, retry on a fallback model, or route to a person |
| Model-written decline | HTTP 200, stop_reason: "end_turn", text that declines the task |
Detect it with an output check and treat it as no answer, never as content to parse |
| Input validation | A 400 error before generation | Fix the request; a retry without changes fails again |
Learn the first row well. The documentation says re-sending a refused request to the same model usually gets another refusal, and that in a conversation you must remove or rephrase the triggering turn before continuing, or later turns keep refusing. To retry elsewhere you can use server-side fallback, a beta request parameter called fallbacks, or client-side fallback through the SDK middleware. Track the refusal rate per category as its own signal.
At Strand & Kepler the origin of those five failures was the harness, not the model: the parser had no branch for a refusal and read silence as consent. The fix is a refusal branch that routes the contract to a lawyer, plus a refusal-rate metric. Note what the wrong fixes would have done. Retrying with backoff repeats the refusal at extra cost, and a prompt asking the model never to refuse changes nothing a classifier decides.
Retrieval-grounding failures: not retrieved, or retrieved and ignored
The last five failures fit neither story. Their notes said the cap was handled, and the reviewer, with no playbook to check against, took the note at its word. But the drafts held no cap clause, or the counterparty's unlimited one, although the drafter knew a cap was required. The drafter is supposed to ground its wording in the clause library through search_clause_library. A retrieval-grounding failure is an answer that is not supported by the sources it should rest on, and it has two distinct shapes with opposite fixes.
In the first, the right passage was not retrieved: it never entered the context, so the model could not use it. The origin is the retrieval stage or the data behind it, such as a query that says "limitation of liability" against a library that titles the clause "aggregate liability ceiling". In the second, the passage was retrieved and ignored: it sat in the context and the output did not use it or contradicted it. The origin is on the generation side, in the prompt, in where the passage sits in a long context, or in the model's handling of conflicting sources. Rewriting the prompt fixes neither a missing passage nor a bad index, and re-indexing fixes nothing when the passage was already there.
Classify the grounding failure before you fix it
The evidence is in the trace. Read which passages the retrieval span returned for the failing run. If the cap clause is absent, it was not retrieved; test retrieval on its own with the same query. If it is present, replay the drafting step with that passage pinned in context, N times. A persistent failure confirms retrieved-and-ignored. Turning on citations helps here: the API returns the cited passages with pointers that are guaranteed valid into the documents you supplied, so you can check in code whether a required clause was used at all. At Strand & Kepler, 3 drafts never retrieved the cap clause because of the naming mismatch, and 2 retrieved it and copied the counterparty's wording instead.
The exam traps
Every trap here changes something before the evidence has named the origin, or fixes the hop where the failure showed instead of the hop where it started.
- ✗ Blaming the model because the wrong text came out of it, and moving to a larger model. ✓ Walk back to the first hop where the needed fact was missing or misused. A larger reviewer still approves a contract whose cap it was never told about.
- ✗ Rerunning a failing case once and closing it as transient when it passes. ✓ Replay with every recorded input pinned, run it enough times to expect several failures, and compare rates. One pass is the expected result for a one-in-fifteen failure.
- ✗ Setting temperature to 0 to make the failure reproducible. ✓ Fix the inputs and measure the output as a distribution. Temperature 0 was never fully deterministic, and current API versions reject the parameter.
- ✗ Adding "always check the liability cap" to the reviewer's prompt. ✓ Pass the mandatory terms across the handoff as structured data from the source, and enforce them with a code check before approval. A prompt cannot supply a fact the context lacks.
- ✗ Treating a refusal as a transient error to retry, or as an empty success to parse. ✓ Branch on
stop_reason: "refusal", discard partial output, and reset the context, fall back to another model or route to a person, with refusals counted separately. - ✗ Tuning the prompt for a passage that was never retrieved, or re-indexing for one that was. ✓ Check the retrieved set in the trace first, then fix the stage the evidence names.
Put it together: diagnose a failure that happens one run in fifteen
You now have every piece: the four origins, the walk back through turns and handoffs, the fixed-input replay, refusals as their own class, and the two shapes of grounding failure. Strand & Kepler's diagnosis sheet for the cap incident shows how they fit on one page; each line is a question you answer from evidence, never from a hunch.
SYMPTOM 41 of ~610 cap-mandatory contracts approved without a liability cap (about 1 in 15)
COHORTS 31 handoff note omits cap | 5 review stop_reason refusal | 5 drafts lack cap clause
FIRST HOP 31: handoff (cap returned by tool, absent from reviewer input) | 5: review parser | 5: retrieval and drafting
ORIGIN harness (free-text handoff) | harness (no refusal branch) | 3 tools/data (not retrieved), 2 model (retrieved, ignored)
REPLAY SK-22817, 100 runs each: fixed cap-less note 100/100 approved; note with cap 0/100; drafter omits cap 8/100
CLEARED playbook data (correct), playbook tool (no errors), reviewer reasoning given its input
FIX structured mandatory terms to reviewer + code check before APPROVED; refusal route to a lawyer; clause naming fix
REGRESSION SK-22817 and one refused contract added as replay cases
The rest of this domain builds on the diagnosis. Incident response (4.2) decides what to do while the failure is live, such as pausing auto-approval or rolling back, and turns the sheet's regression line into evaluations and alerts. Trace analysis at scale (3.3) is how you find a cohort like these 41 in millions of traces in the first place, and retrieval architecture (2.4) is where a not-retrieved finding gets its lasting fix.
Key takeaways
- ✓ A failure starts at the first hop where the needed information went missing or was misused, which is rarely the hop where it became visible.
- ✓ Classify the origin from evidence: model output misuses correct context, the harness fails to deliver it, tools fail or misreport, data is wrong at the source.
- ✓ In multi-turn and multi-agent systems, find the first turn or handoff that lost the fact, and carry hard constraints across boundaries as data from the source with a code check.
- ✓ Treat non-deterministic failures as rates: replay with every recorded input pinned, run N times and compare rates while changing one component at a time.
- ✓ A refusal is an HTTP 200 with no usable answer: branch on
stop_reason: "refusal", discard partial output and handle it with a context reset, a fallback model or a human route. - ✓ Split grounding failures into not retrieved and retrieved and ignored by reading the retrieved set in the trace before choosing a fix.
Practise this
Practice questions for CCDV-P are being written and are not in this course yet. Read this lesson on the web to answer its check questions, with every option explained: https://claude.termidy.com/learn/ccdv-p/debugging-incident-response/complex-failure-diagnosis/.