> ## Documentation Index
> Fetch the complete documentation index at: https://circuitcheck.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Circuit validator

> Test whether graph features cause the behaviour (a switch) or only reflect it (a readout).

An attribution graph ranks features by influence, and influence is not necessity. The validator intervenes on groups
of features and compares each effect with the same intervention on features that are *not* in the circuit.

<video controls preload="metadata" src="https://mintcdn.com/circuitcheck/8B_KsgGdd3MlDck5/videos/validate.mp4?fit=max&auto=format&n=8B_KsgGdd3MlDck5&q=85&s=3366d1c883a0745ae811f77a16971224" title="The validator in one minute">
  <track kind="captions" src="https://circuitcheck.mintlify.site/videos/validate.vtt" srcLang="en" label="English" default />
</video>

## The checks

**1. Ablation**

Set the group's features to 0 at their positions. A feature the output needs moves the metric.

**2. Steering**

Multiply them by `steer_scale` (3 by default). A feature that drives the output moves it again.

**3. Counterfactual patch (optional)**

Give them the values they take on a prompt with a different answer. A switch moves the output toward that answer.

**4. Controls**

Repeat each intervention on `n_controls` random feature sets (same layer and position where possible) and on
`n_controls` sets matched by write size (|activation| x decoder norm). An effect counts only if it beats both
kinds at p ≤ alpha.

**5. Explanation swap (optional)**

Gao's swap test: replace each feature with the value its explanation predicts, written as a small Python rule,
and measure how much of the feature's effect survives.

## Verdicts

| Verdict | Meaning |
| - | - |
| `switch` | Needed for the output, beats matched random features, and (with a counterfactual) patching it moves the output toward the counterfactual |
| `partial` | Needed and specific, but the patch does not move the output far enough |
| `backup` | Not needed, but pushing or patching it moves the output: a sufficient path with redundancy elsewhere |
| `nonspecific` | Switching it off matters, but matched random features matter as much |
| `readout` | Active and highly attributed, but no intervention moves the output beyond controls |

## On a real model

```python gpu theme={null}
from circuit_tracer import ReplacementModel

from circuitcheck.tracer import TracerBackend, nodes_for_units
from circuitcheck.validate import GroupSpec, logit_diff, validate

model = ReplacementModel.from_pretrained("google/gemma-2-2b", "gemma")
backend = TracerBackend(model)  # attention responds to interventions; freeze_attention=True for direct effects

prompt = "Fact: the capital of the state containing Dallas is"
counterfactual = "Fact: the capital of the state containing Oakland is"
nodes = nodes_for_units(backend, prompt, [(20, 15589), (16, 25), (14, 2268)], positions="all")
metric = logit_diff(backend.token_id(" Austin"), backend.token_id(" Sacramento"), " Austin", " Sacramento")

report = validate(backend, prompt, nodes, metric=metric, counterfactual=counterfactual, n_controls=20)
```

Or from the command line, with features given as `layer:feature@position`:

```bash gpu theme={null}
circuitcheck validate --model google/gemma-2-2b --transcoders gemma \
  --prompt "Fact: the capital of the state containing Dallas is" \
  --counterfactual "Fact: the capital of the state containing Oakland is" \
  --features 20:15589@9,16:25@9 --target " Austin" --contrast " Sacramento" --html validate.html
```

## Groups

By default the validator tests all given features together, then each alone. Pass `groups=` to test supernodes:

```python theme={null}
from circuitcheck.validate import GroupSpec, logit_diff, validate
from circuitcheck.validate.toy import demo, demo_nodes

backend = demo()
nodes = demo_nodes(backend)
groups = [GroupSpec(name="switch + readouts", nodes=nodes[:3]), GroupSpec(name="backup pair", nodes=nodes[3:])]
metric = logit_diff(backend.token_id(" Austin"), backend.token_id(" Sacramento"))
report = validate(backend, "dallas", nodes, metric=metric, groups=groups, counterfactual="oakland")
print([(g.name, g.verdict.value) for g in report.groups])
```

> [!TIP]
>
> The backup pair shows why single-feature ablation can mislead. Each feature alone is redundant, so ablating one
> does nothing. Steering either one still moves the output, which earns the `backup` verdict rather than `readout`.

## Parameters

**n\_controls** `int` (default: 20)

Control sets per kind. The smallest possible p-value is 1 / (n + 1), so below 19 nothing can reach p ≤ 0.05. The
report notes it when that happens.

**steer\_scale** `float` (default: 3.0)

Multiplier for the steering check.

**thresholds** `Thresholds`

`min_effect` (0.2 of the scale), `alpha` (0.05), `patch_min` (0.3 of the gap), `explained_min` (0.8). The scale is
the clean-to-counterfactual gap, or the clean metric's size without a counterfactual. Every rule is printed in the
report.

**rules** `dict[(layer, feature), str]`

Explanation rules for the swap test: Python source defining `predict(tokens, i) -> float`, run in a restricted
namespace that rejects imports, dunder access and unknown names before running.

## Reproducing the circuits episodes

`examples/modal/live_checks.py` runs the validator with `TracerBackend` on the two organisms from steerlab's circuits episodes:

* **RL hack:** the ten features the graph diff picks, at three comment slots.
* **Password lock:** the study's ten claimed features, with the password prompt as the counterfactual.

The results are in `examples/data/live/` and checked by `tests/test_live_results.py`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.