Skip to main content

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

  1. Edit an existing module under src/mechbench_schema/, or add a new module (following the domain-axis convention).
  2. 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).
  3. Run python scripts/codegen.py. This writes ts/src/schema.json and ts/src/generated.ts.
  4. 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 produced MechbenchPath; Phase 4 (content-addressing grammar) remains open and coordinates with 000162 (the DAG-solver epic in mechbench-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

mechbench_schema-0.13.0.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mechbench_schema-0.13.0-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

File details

Details for the file mechbench_schema-0.13.0.tar.gz.

File metadata

  • Download URL: mechbench_schema-0.13.0.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.1

File hashes

Hashes for mechbench_schema-0.13.0.tar.gz
Algorithm Hash digest
SHA256 7aa794a59d0cb306dd46cbffd1ecc2fc3da6b8e0d27c613c93877cfbd629d557
MD5 296d924f0545d8d39636ed2d1efd0096
BLAKE2b-256 2be0b68ef7625d546ef57d7d112d4e3894091fe0878f76ad4fcf409c40e49cd8

See more details on using hashes here.

File details

Details for the file mechbench_schema-0.13.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mechbench_schema-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8099320d43c47aaa5674a0df2b17fb60080a9cfff8d5f61e988585e70161a6df
MD5 adbab7f64b59a25e1620ad572fa99623
BLAKE2b-256 d15ae83d2050ce03c0b5b32ad89d33a32686528118fd3210bc61ff3adfb273fb

See more details on using hashes here.

Release history Release notifications | RSS feed

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

This release

0.13.0 This release

2 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