Search⌘ K
AI Features

Harness Hooks, Trace Inspection, and A/B Ablation Testin

Explore how to prove the cause of AI context failures instead of treating classifier labels as guesses. You will capture model inputs with pre-inference and post-tool hooks, create safe one-item ablations, compare failure verdicts, and measure whether removing conflicting or distracting context improves answers.

We'll cover the following...

In the previous lesson, we built classify_failure(). It runs four checks in a fixed order and gives a failing trace one label. On the clash trace, it told us that get_deploy_log says the latest checkout deploy is v2.31 at 14:02, while a message from the incident thread says v2.30 at 13:40.

A label tells us where to look, but it’s still only a guess about the cause. To prove the cause, we need to run the trace twice: once as it is, and once with the suspected item removed. If the failure goes away only when that one item is gone, we’ve shown that the item caused it.

In this lesson, we’ll do that comparison by hand first. Then we’ll add hooks that save what the assistant actually saw, build a harness that runs the comparison safely, and use a model call to check that the answer itself improves.

A label is a hypothesis

When the classifier says “clash”, it means two sources disagree on a fact. It doesn’t yet prove that the disagreement is what made the answer wrong. Other things in the same trace could also be responsible.

The way to test this is called an ablation. We take a full trace and make a trimmed copy that differs by exactly one suspected item. Then we run both through the same check and compare the results. Because only one thing changed, any change in the result can be pinned on that one item. That’s what turns “clash looks like the cause” into “clash is the cause.”

Try one ablation by hand

Before we build any tooling, let’s do this once by hand on the clash trace from the previous lesson. Its fact_values list has two entries for the same key, latest_checkout_deploy. We’ll copy the trace and leave out only the incident-thread entry. Everything else stays the same.

manual_ablation.py · Python 3.14.0
from clash import CLASH_TRACE, check_clash
trimmed_trace = {
"query": CLASH_TRACE["query"],
"tool_call": CLASH_TRACE["tool_call"],
"fact_values": [fact for fact in CLASH_TRACE["fact_values"] if fact[0] != "incident-thread"],
}
if __name__ == "__main__":
print("full: ", check_clash(CLASH_TRACE))
print("trimmed:", check_clash(trimmed_trace))
print("fields that changed:", [key for key in CLASH_TRACE if CLASH_TRACE[key] != trimmed_trace[key]])

In the code above:

  • Line 1: We import CLASH_TRACE and check_clash() from the previous lesson.

  • Lines 3–7: We build trimmed_trace. It copies query and tool_call unchanged and keeps every fact except the one from incident-thread.

  • Lines 10–11: We run the same check_clash() on both traces.

  • Line 12: We list the fields that differ between the two traces, to confirm ...