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.15.0.tar.gz (35.2 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.15.0-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mechbench_schema-0.15.0.tar.gz
Algorithm Hash digest
SHA256 3cec7ccd37d205020868c6214f96343dbc102f51447b7fbce30bb1aa03f2cc1d
MD5 97ec828b893d81b7646e0e364e28bc04
BLAKE2b-256 35ad3628f5ad594b61b5866a3fb1ea4324ebe63b51a5bc8ba3124efdde7cff1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mechbench_schema-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d81fcc684eb3f6e0407e5433859ad2714a7cf101c8ae9d87c522fa242696b02
MD5 a1c53dbf57f5960825aea7c22abeccc5
BLAKE2b-256 9920a5e4b73680eb64063ecd645cc0feddc00fa0b6e03109283d607989330586

See more details on using hashes here.

Release history Release notifications | RSS feed

0.16.0

2 files

This release

0.15.0 This release

2 files

0.14.0

2 files

0.13.0

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