mechbench-schema
The typed emission contract for the mechbench family.
Pydantic models are the single source of truth. TypeScript bindings are generated from them; both halves are published from this one repo to two package registries.
| Consumer | Registry | Package |
|---|---|---|
| Python (core, agent, remote, experiments) | PyPI | pip install mechbench-schema |
| TypeScript (ui, skills) | npm | npm install mechbench-schema |
The two packages share a name and a version. CI regenerates the TS bindings and fails on drift, so the two halves cannot disagree.
Organization: by domain axis, not by consumer
Modules are named after the indexing axis of the records they carry, not after who renders them. This keeps the schema from becoming "chart data" just because charts are the current biggest consumer; the same records drive CSV exports, agent tool surfaces, the memoization cache, and anything else downstream.
| module | category | archetypal records |
|---|---|---|
per_layer_data |
indexed by layer |
ablation damage, DLA diffs, convergence summaries |
per_head_data |
indexed by (layer, head) |
per-head DLA, OV rank-0 singular values |
attention_trace |
indexed by (layer, head, pos_from, pos_to) |
attention patterns |
per_layer_per_position_data |
indexed by (layer, position) |
logit-lens trajectories, causal-trace grids |
vector_data |
atomic: one direction in residual space | captured / steering / probe / centroid vectors |
cluster_data |
collection of vectors with aggregate stats | named clusters, cross-cluster statistics |
identity |
path grammar | MechbenchPath validated-string type |
Every payload model is part of a discriminated union keyed by kind (or origin for vectors), so the UI can dispatch rendering on the tag and the DAG solver can reason about compatible outputs.
Repo layout
mechbench-schema/
├── src/mechbench_schema/ # Pydantic models — the source of truth
│ ├── __init__.py # __all__ + __schema_all__
│ ├── attention_trace.py
│ ├── cluster_data.py
│ ├── identity.py
│ ├── per_head_data.py
│ ├── per_layer_data.py
│ ├── per_layer_per_position_data.py
│ └── vector_data.py
├── ts/ # published to npm as "mechbench-schema"
│ ├── package.json
│ ├── tsconfig.json
│ └── src/
│ ├── index.ts
│ ├── generated.ts # codegen output — DO NOT EDIT
│ └── schema.json # consolidated JSON Schema — codegen output
├── scripts/
│ └── codegen.py # Pydantic → JSON Schema → TypeScript
├── pyproject.toml # published to PyPI as "mechbench-schema"
└── README.md
Editing the contract
- Edit an existing module under
src/mechbench_schema/, or add a new module (following the domain-axis convention). - Export the new type from
src/mechbench_schema/__init__.py. Add it to__all__for Python consumers and to__schema_all__for codegen (wire types only). - Run
python scripts/codegen.py. This writests/src/schema.jsonandts/src/generated.ts. - Commit everything in one PR — Python source, generated JSON Schema, generated TypeScript.
CI runs codegen and git diff --exit-code ts/src/schema.json ts/src/generated.ts. A drifted PR cannot land.
The codegen uses json-schema-to-typescript (via npx) for the TS emission. Python → JSON Schema comes from Pydantic's built-in model_json_schema() (for BaseModel subclasses) and TypeAdapter(...).json_schema() (for type aliases like the discriminated unions).
Install (Python)
pip install mechbench-schema
from mechbench_schema import LayerAblationPayload, DlaSweepPayload
payload = LayerAblationPayload(
experiment="step_02_layer_ablation",
description="Per-layer ablation damage on FACTUAL_15.",
model="mlx-community/gemma-4-E4B-it-bf16",
n_layers=42,
global_layers=[5, 11, 17, 23, 29, 35, 41],
prompts=[...],
aggregates=LayerAggregates(mean=[...], median=[...]),
)
# Emit to JSON — mode="json" canonicalizes datetimes, bytes, etc.
import json
path.write_text(json.dumps(payload.model_dump(mode="json"), indent=2))
Install (TypeScript)
npm install mechbench-schema
import type { LayerAblationPayload, Vector, MechbenchPath } from "mechbench-schema";
const payload: LayerAblationPayload = JSON.parse(text);
// All fields, discriminated unions, and nested types come from the generated bindings.
Identity grammar
MechbenchPath is the type used to address every object in the mechbench family — charts, articles, experiments, corpuses, probes, cached DAG intermediates. Five categories:
<owner>/<project>/<folders>/<leaf>— user-named~canonical/<area>/<path>/<leaf>— human-readable aliases for globally-shared content~system/<area>/<path>/<leaf>— platform / first-party~hash/<algo>:<digest>— global content-hashed (deduplicated across users)<owner>/<project>/~hash/<algo>:<digest>— workspace-scoped content-hashed
Full spec in the meta repo's IDENTITY_AND_NAMESPACING.md. The Python side (mechbench_schema.identity) owns the authoritative validator; a mirror implementation lives in mechbench-ui/src/lib/mechbenchPath.ts for UI-side early failure.
Why one repo, two publications
Schemas that live in two repos drift. The only invariant that matters — "Python and TS agree on the shape" — is enforced by keeping the source in one place and generating the target. Consumers never need the other language's toolchain to install; pip and npm each resolve to a clean single-language package.
See the family overview for the rationale behind this and other multi-repo decisions.
Status
Version 0.8.0. Seven modules in active use; the legacy records.py holding pen was retired when the domain-axis reorg completed. mechbench-experiments' two exporters (step_02_layer_ablation, step_33_dla_factual_sweep) emit via Pydantic models; mechbench-ui's chart interfaces are one-line aliases over the generated TS types.
Open work lives in the meta repo's tasks/mechbench-schema/ directory. The two notable open epics downstream of this repo:
000161— compact binary formats for records at rest and in transit (safetensors for tensor-bulk, parquet for record-collections).000163— the identity-and-namespacing epic that producedMechbenchPath; Phase 4 (content-addressing grammar) remains open and coordinates with000162(the DAG-solver epic inmechbench-compute).
License
MIT.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mechbench_schema-0.16.0.tar.gz.
File metadata
- Download URL: mechbench_schema-0.16.0.tar.gz
- Upload date:
- Size: 35.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e94f00e9e7aec4317429a526525ec38aae06c28b5366d11c1fefdc667a86157
|
|
| MD5 |
5a5d7250198cdd8fd31ac99338328db9
|
|
| BLAKE2b-256 |
b9b51fce13acf1ac3c3e9350cdf7a87aeb0a9a98ab1f3fc16f30d60e9d8792b1
|
File details
Details for the file mechbench_schema-0.16.0-py3-none-any.whl.
File metadata
- Download URL: mechbench_schema-0.16.0-py3-none-any.whl
- Upload date:
- Size: 39.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53ccffbf46867585ce4a3199a45b7c6ed9e0982d3bde1676ae1e99252fd97f71
|
|
| MD5 |
120d3d755e3f0fd693875612f782c221
|
|
| BLAKE2b-256 |
79576b3ef1a789107587d4331bf68d1de2e46bfe2a9ebcf11ae8221c368915d1
|