Mechanistic interpretability for transformers: causal circuit discovery, measured faithfulness (sufficiency, comprehensiveness, F1) and draft EU AI Act Annex IV documentation. Includes an AI-system investigation layer. Dual-licensed (MIT core + BSL 1.1 compliance engine and investigation layer).
pip install glassbox-mech-interp==4.7.0 Copy PIP instructions
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.
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.
Every claim in this README is tracked, with its evidence and status, in ASSURANCE.md.
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.
The investigation layer (glassbox.v7) ships in the same package from 4.6.0. To re-run the experiments or reproduce an evidence package, install from source, since the experiments and recipes are not in the wheel:
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.
from glassbox import AnnexIVReport report = AnnexIVReport(model_name="gpt2", system_purpose="...", provider_name="Acme Corp", provider_address="...") report.add_analysis(result) report.save_json("annex-iv.json") 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, CHECKS FAILED. That refusal is intended; the tool won't certify what it can't explain. ("CHECKS FAILED" is Glassbox's own quality gate, not a legal ruling. Before 4.7.0 it was labelled "NON-COMPLIANT".)
Full methodology and raw data: BENCHMARKS.md. Reproduce with scripts/benchmark.py.
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.
Providers of high-risk AI systems must draw up Annex IV technical documentation (Article 11 of Regulation (EU) 2024/1689). Glassbox drafts the 9-section structure from one analysis: measured evidence fills what it can, and the rest is marked for the provider. Report packs also map to the NIST AI RMF and ISO/IEC 42001.
Application dates for high-risk obligations were amended by Regulation (EU) 2026/1744 (the Digital Omnibus on AI). Check the current legal text for the dates that apply to your system; this README does not restate them.
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.
Research stage. In the PyPI package from 4.6.0. 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:
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 live demo has two worked examples: this RAG incident on GPT-2, and a simulated tool-using agent whose true effects are known and shown next to Glassbox's answer.
On your own system, a "change" is any configuration difference you can switch on and off and re-run: model version, prompt, retrieval setting, framework or tool version. You supply a function that runs your system under a given configuration and records a trace, plus one that reads the outcome; glassbox.v7.intervene.run_interventions does the rest. Only the change types listed in the experiments below have been tested.
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.
A first divergence shows where runs differ, not why. Causal statements need the controlled interventions above, case by case.
Open docs/anatomy/glassbox-bench-light.html in a browser to scrub through it (details in docs/anatomy/README.md). The three dial readings are the IOI benchmark on GPT-2 small from Measured results; the per-head scores and which heads are lit are drawn for the picture, not taken from a run.
Two paths, two maturity levels. Path 1 (explain one decision) is released on PyPI. Path 2 (find out why an AI system changed) is the investigation layer, research stage; see above.
Find the circuit. Score every head in 3 passes, keep the few that carry the decision.
Test it by taking it out. Faithfulness is computed by re-running the model with parts ablated, not asserted.
Which change mattered? Switch each change on alone and revert each alone. Where runs first differ is not why.
Run the built-in demo, a small RAG incident with three simultaneous changes:
Re-install either with git clone .claude/skills/ .
The bench figure in docs/anatomy/ is built with anatomy; the three English illustrations in docs/illustrations/ follow the Xiaohei style and are hand-drawn vectors with their generator included, not AI-generated art.
Contributions are welcome. See CONTRIBUTING.md and our Code of Conduct, and run the suite with pytest --cov=glassbox -v.
Glassbox is dual-licensed. NOTICE holds the authoritative file-by-file map.
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.
@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. Project links Dashboard Documentation Homepage Paper Repository Key dates PyPI data Data sourced directly from PyPI's database. Released: Nov 8, 2026 Latest release 1 maintainer PyPI data Data sourced directly from PyPI's database. Glassbox_AI Credits Data verified by PyPI on Nov 8, 2026 Data provided by the project maintainers, verified at the time the release was uploaded to PyPI. Confirms that the provided email matches a verified, public email address on a PyPI user account associated with the project. Author: Ajay Pravin Mahale
Both files in this release have provenance metadata.
MIT License, Other/Proprietary License (MIT AND LicenseRef-BUSL-1.1)
all api compliance dev hf jupyter mlflow notify sae telemetry
mechanistic-interpretability transformers circuits attribution-patching edge-attribution-patching logit-lens sparse-autoencoders sae composition-scores attention-heads explainability XAI LLM GPT-2 circuit-discovery alignment eu-ai-act annex-iv compliance audit black-box-audit regulatory-compliance causal-scrubbing distributed-alignment-search das hessian layernorm-correction false-discovery-rate benjamini-hochberg polysemanticity multi-corruption held-out-validation sample-size-gate interpretability circuit-faithfulness acdc automated-circuit-discovery grouped-query-attention gqa rmsnorm llama mistral cross-model multi-architecture
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Both files in this release have been uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




