Skip to main content
Glassbox — see inside the black box

Glassbox

Prove what your model actually did, and find out why your AI system changed.

Trace the circuit behind a model's decision, measure how faithful that explanation is, and draft the EU AI Act Annex IV technical documentation from one function call, on open-weight models. A newer investigation layer compares runs of an AI system before and after a change and tests which change actually mattered.

PyPI version PyPI downloads License: MIT core License: BSL 1.1 Python 3.8+ arXiv HuggingFace Space Website

Website · Live Demo · Paper · PyPI · User Guide · What is proven


Most explainability tools describe a model from the outside and can't tell you whether the explanation is true. Glassbox reads the inside. It ranks every attention head by its causal effect on a decision, keeps the minimal circuit that drives it, and then measures how faithful that circuit is by re-running the model with parts ablated.

The finding behind the tool: a model's confidence is essentially uncorrelated with how faithful its explanation is (r = 0.009). An auditor who relies on a confidence score is relying on something unrelated to faithfulness. Faithfulness has to be measured, not assumed.

Two parts, two maturity levels:

Part What it does Status
Circuit + faithfulness + Annex IV Explains one model decision and drafts documentation Released on PyPI (glassbox-mech-interp 4.5.1)
Investigation layer (glassbox/v7/) Explains why an AI system's behaviour changed between two versions In this repository, not yet in a PyPI release; research stage (see below)

Every claim in this README is tracked, with its evidence and status, in ASSURANCE.md.


Install

pip install glassbox-mech-interp

Extras: pip install "glassbox-mech-interp[compliance]" (Annex IV engine) · [jupyter] (notebook widget) · [dev] (tests + lint). No install? Try the live demo on Hugging Face.

To use the investigation layer, install from source:

git clone https://github.com/designer-coderajay/glassbox-mech.git
cd glassbox-mech
pip install -e ".[dev]"

60-second quickstart: explain one decision

from transformer_lens import HookedTransformer
from glassbox import GlassboxV2

model = HookedTransformer.from_pretrained("gpt2")   # any open-weight transformer
gb    = GlassboxV2(model)

result = gb.analyze(
    prompt    = "When Mary and John went to the store, John gave a drink to",
    correct   = " Mary",
    incorrect = " John",
)

print(result["circuit"])         # [(9, 9), (9, 6), ...]  <- (layer, head)
print(result["faithfulness"])    # {'sufficiency': 1.0, 'comprehensiveness': 0.543, 'f1': 0.704, ...}

Measured on GPT-2 IOI with the current build: suff 1.00 · comp 0.543 · F1 0.704 · Grade B, in about 1.8 s on an Apple M1 Pro.

What you get back

  • The circuit: which attention heads causally drive the decision, ranked.
  • Faithfulness metrics and a grade (A–D): sufficiency, comprehensiveness and their F1, computed by ablation, so they are reproducible rather than asserted.
  • A plain-English explanation and a self-graded evidence tier.
  • An EU AI Act Annex IV file: 9 sections, 8 auto-filled from the evidence and content-hashed. §8 (Declaration of Conformity) is left for a human to sign.
from glassbox import build_annex_iv_vault
vault = build_annex_iv_vault(gb_result=result, model_name="gpt2", provider="Acme Corp",
                             output_json="annex-iv.json", output_html="annex-iv.html")

Honest by design

When a model can't do a task, Glassbox says so instead of inventing a clean story. Point it at raw GPT-2 for a credit decision and it finds no faithful circuit: F1 0.00–0.08, Grade C, NON-COMPLIANT. That refusal is intended; the tool won't certify what it can't explain. ("NON-COMPLIANT" here is Glassbox's own quality gate, not a legal ruling.)

Measured results

Value
Method Attribution patching (activation difference × gradient): 3 forward passes, not a search
Speed About 1.8 s for GPT-2 Small on an Apple M1 Pro (4.2 s on an 8-core CPU); 15–37× faster than ACDC across the GPT-2 family, depending on circuit size and hardware (see BENCHMARKS.md)
IOI benchmark (GPT-2 Small, default circuit) suff 1.00 · comp 0.543 · F1 0.704 · Grade B (1-head circuit). Full 26-head Wang et al. circuit: suff 1.00 · comp 0.47 · F1 0.64
Key finding Confidence–faithfulness correlation r = 0.009
Validated scale 82M → 12B across 9 architecture families (10 model series)
Quality 1,288 tests passing, 76% coverage (full run 2026-10-12; see docs/VALIDATION_LOG.md)

Full methodology and raw data: BENCHMARKS.md. Reproduce with scripts/benchmark.py.

How it compares

Approach Faithfulness measured? Needs open weights? Speed (GPT-2)
Glassbox (attribution patching) ✅ suff / comp / F1 Yes 1.8 s
ACDC (Conmy et al. 2023) ✅ Yes ~65 s
SHAP / LIME (black-box) ❌ no guarantee No (works on APIs) varies
Confidence scores ❌ (r = 0.009) No instant

Model coverage

Validated end-to-end on nine architecture families (ten model series; Yi uses the Llama architecture) from 82M to 12B: GPT-2, Pythia/GPT-NeoX, GPT-Neo, OPT, Llama-3, Mistral, Gemma-2, Qwen2/2.5, Yi and Phi-3, with grouped-query attention and RMSNorm handled correctly.

  • Beyond about 13B: gradient-based attribution needs a multi-GPU cluster. This is implemented but not yet validated live.
  • Closed APIs (GPT-4, Claude, Gemini): only a weaker black-box tier is available, because faithfulness can't be measured without the weights.

See docs/VALIDATION_LOG.md.

EU AI Act: Annex IV

Providers of high-risk AI systems must draw up Annex IV technical documentation (Article 11). Glassbox auto-fills 8 of the 9 sections from the model's measured behaviour. It maps to Article 13 (transparency), Article 72 (post-market monitoring) and Article 9 (risk), with a cross-walk to the NIST AI RMF and ISO/IEC 42001.

Dates and penalties:

  • Under current law, high-risk obligations apply from 2 August 2026.
  • The Digital Omnibus (provisionally agreed 7 May 2026, pending adoption) would defer Annex III to 2 December 2027. Plan against both dates.
  • The penalty for documentation non-compliance is up to €15M or 3% of global turnover (Art. 99(4)).

Glassbox produces evidence and documentation, not a conformity declaration. It is not legal advice and does not by itself make anyone compliant. The EU AI Act does not require mechanistic interpretability. See Legal Notices.

Investigating why an AI system changed

Research stage. In the repository, not yet in a PyPI release. Licensed under BSL 1.1.

When a RAG assistant or an agent starts behaving differently after a week of changes (new index, edited prompt, new framework version), the investigation layer:

  1. Records each run as a local trace: nested spans, tool calls and hashed content. Raw text is not stored by default.
  2. Compares many runs before and after the change. A noise-aware group diff separates real differences from run-to-run sampling noise.
  3. Tests each change alone and each change reverted alone, then reports which changes moved the outcome and which did not.
  4. Packages the result as an evidence bundle with a sha256 manifest that anyone can verify.

Try the built-in demo, a small RAG incident with three simultaneous changes:

python -m glassbox.v7.investigate demo --out demo_out --scorer gpt2

It writes a plain-language REPORT.md and an evidence package. The same investigation is available as a tab in the Gradio demo (dashboard/).

What has been tested so far

Each experiment was pre-registered: the protocol was committed before the code and the run, and the results were committed unchanged. All were designed and run by the author, with the cause known in advance; none has yet been reproduced independently.

Experiment Result Status in ASSURANCE.md
1. Controlled RAG fault (stale index) First divergence at retrieval for 4/4 affected questions; silent on 4/4 unaffected; recovery confirmed 8/8 Experimentally supported
2. Real third-party bug (llama_index #21033) Difference localised to retrieval; fix confirmed in a later version Experimentally supported
3. Group diff, single injected change, N = 30 Localised in 0.79 of replications against a pre-declared 0.80 bar: FAIL Refuted
3b. Same, with redundant fields merged 0.875 localised; false alarms ≤ 0.02 at every N from 10 to 50 Experimentally supported
4. Interventions, synthetic pipeline Real cause blamed in 0.825 of replications; inert co-change blamed in ≤ 0.025 Experimentally supported
5. Interventions, GPT-2 RAG (3 co-changes) Known fault blamed 4/4; zero-effect and inert changes never blamed. True template effects of 0.108 and 0.046 were not detected Experimentally supported
6. Same investigation on Pythia-160m, OPT-125m, Qwen2.5-0.5B Every large true effect blamed (3/3, 3/3, 4/4); none of 36 zero effects. Detected effects of about 0.41; missed effects of about 0.16 Experimentally supported
7. Tool-using LLM agent (duplicate-email incident) The agent almost never acted, so the test could not be scored: INCONCLUSIVE Unresolved
7b. Same incident with an instruction-tuned agent (Qwen2.5-3B-Instruct) Large real cause blamed 4/4; inert change never blamed; hidden retries traced. PASS in two runs. The change was mostly "stopped sending", not duplicates. A mid-sized cause (about 0.34) was found 2/4 Experimentally supported (second run matched every decision; 6th-decimal differences traced to floating-point summation order by a pre-registered check)
8. Same fault on a second stack (LlamaIndex, traced by OpenInference/OpenTelemetry, imported from OTLP) Import lossless 32/32; unchanged diff engine localised the fault 4/4, silent 4/4, recovery 8/8, deterministic 8/8; Glassbox traces pass the official OTLP schema 32/32 Experimentally supported (retrieval only; one framework)
9. Re-run 8 packaged experiments on Linux x86-64 (Kaggle) instead of the original macOS arm64 7/8 reproduced exactly (incl. Experiment 3's FAIL). Experiment 6: every decision the same, but one sampled run flipped from tiny float differences, so FAIL as pre-registered Refuted (same-author; Gate 5 not met)
9b. Same 8 packages on a fresh GitHub Actions runner (AMD EPYC), judged on gated decisions 8/8 same decisions; 7/8 also exact. Experiment 6 differs only in floats (max 0.004). PASS Experimentally supported (same-author; decision level; criterion chosen after Experiment 9, stated openly)
10. Benchmark: 32 sealed-seed known-cause incidents (GPT-2 RAG + synthetic agent), Glassbox vs two automated baselines Exact diagnosis 21/28 (0.75) vs 0.50 and 0.00; zero-effect causes blamed 1/299; false alarms 1/48; fix verified 20/24. All 5 pre-declared criteria PASS. Missed 4 units where co-changes cancelled out; small effects mostly not diagnosed Experimentally supported (author-designed benchmark; 26/28 positives from one family; not blind)

Not shown yet:

  • that it finds unknown causes in real production systems;
  • that it works across frameworks in general (so far: one second stack, retrieval only);
  • that it saves engineers time. There are no external users so far.

A first divergence shows where runs differ, not why. Causal statements need the controlled interventions above, case by case.

How it works (circuit analysis)

  1. Discover: rank every attention head by causal effect (attribution patching, 3 passes).
  2. Verify: keep the minimal circuit, then measure sufficiency and comprehensiveness against full ablation.
  3. Document: grade the result and write the content-hashed Annex IV file.

Documentation

User Guide Full walkthrough, all examples, complete API reference
BENCHMARKS.md Methodology, hardware, reproducible numbers
ASSURANCE.md Every claim with its evidence and status (supported, refuted, unresolved, planned)
Methodology & Assurance What's proven vs measured vs hypothesised
Trace spec The investigation layer's trace format
CHANGELOG.md Release history
Live docs site Interactive overview

Limitations

  • White-box only for circuits: circuit analysis needs weights, activations and gradients. Open models are fully supported; closed APIs get the black-box tier only.
  • Decisions, not free-form chat: circuit analysis needs a contrast between two outcomes to attribute against.
  • Offline and sampled: Glassbox audits representative decisions for documentation and monitoring. It is not a real-time monitor on every request.
  • Faithful ≠ fair: it measures whether the explanation matches the computation, not whether the decision is correct or unbiased.
  • Investigation layer:
    • so far validated only on small open-weight models and author-designed incidents;
    • small effects (about 0.16 and below at 30 runs per configuration) can be missed;
    • redaction of trace content is best-effort;
    • a hash manifest proves integrity, not truth.

Contributing

Contributions are welcome. See CONTRIBUTING.md and our Code of Conduct, and run the suite with pytest --cov=glassbox -v.

License

Glassbox is dual-licensed. NOTICE holds the authoritative file-by-file map.

Component License Summary
Interpretability core (circuit discovery, faithfulness, everything not listed below), tests, examples, docs MIT (LICENSE) Use, modify and redistribute freely, including commercially
Compliance engine: compliance.py, circuit_diff.py, risk_register.py, bias.py, audit_log.py, cross_model.py BSL 1.1 (LICENSE-COMMERCIAL) See the summary below
Investigation layer: glassbox/v7/, dashboard/v7_investigation.py BSL 1.1 (from 2026-10-11) See the summary below

BSL 1.1 summary:

  • Free for non-production use, and for production use inside your own organisation (for example, investigating or documenting your own AI systems).
  • Needs a commercial license to offer a compliance, AI-governance, AI-investigation, debugging or observability service or product to third parties.
  • Converts to Apache-2.0 four years after each version is first published.
  • Copies of cross_model.py and the investigation layer obtained before 2026-10-11 remain under the terms they were published with.

The circuit-discovery and faithfulness core stays MIT and is never feature-gated. For commercial licensing, contact mahale.ajay01@gmail.com. Academic and non-profit research use may qualify for a no-cost license.

Citation

@article{mahale2026causally,
  title         = {Causally Grounded Mechanistic Interpretability for LLMs with Faithful Natural-Language Explanations},
  author        = {Mahale, Ajay Pravin},
  year          = {2026},
  eprint        = {2603.09988},
  archivePrefix = {arXiv},
  primaryClass  = {cs.CL},
  doi           = {10.48550/arXiv.2603.09988}
}

See inside the black box: causal circuits, measured faithfulness, EU AI Act Annex IV, and evidence for why an AI system changed.

Metadata

Release files for glassbox-mech-interp 4.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for glassbox-mech-interp 4.6.0
File Size Uploaded
glassbox_mech_interp-4.6.0.tar.gz 485.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for glassbox-mech-interp 4.6.0
File Interpreter ABI Platform
glassbox_mech_interp-4.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 862.4 kB

Release files / glassbox_mech_interp-4.6.0.tar.gz

Download URL glassbox_mech_interp-4.6.0.tar.gz
Size 485.0 kB
Tags Source
SHA-256 checksum
How to use checksums
641c503c851b6b4bf6e400d28847315ec492440fd241ee3221d8f3809877ae81
BLAKE2b-256 checksum
How to use checksums
40bd9c8567d8b5148c7e144055e7730dd95bb4e95549313c5064bd19598ec0fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / glassbox_mech_interp-4.6.0-py3-none-any.whl

Download URL glassbox_mech_interp-4.6.0-py3-none-any.whl
Size 377.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7f0121a245ad79608606e22738452e5938ff77a724a32cc30fafe1e05ba0a5f
BLAKE2b-256 checksum
How to use checksums
137c011741d8856b8174120bb628ece2dc6d48927feda2405171c780c0c9f508
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

4.6.0 This release

2 release files

4.5.1

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.3.1

2 release files

4.3.0

2 release files

4.2.6

2 release files

4.2.5

2 release files

4.2.4

2 release files

4.2.3

2 release files

4.2.2

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.7.0

2 release files

3.6.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.2.1

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page