Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.4.2 instead.
Reason given by maintainers: Missing grid/_statecharts data files: CFG grammar loading fails with FileNotFoundError. Use grid-guardrail>=0.4.2

GRID - Grammar-Railed Decoding

CI PyPI DOI License

Constrained decoding for LLMs with provable guarantees and no silent errors: every constraint is either enforced by the token mask, or named in the output. Nothing is quietly dropped.

GRID compiles grammars (SQL-first; JSON Schema via grid.jsonschema) into LALR(1) tables with constrained terminals, and masks tokens through a configuration-keyed viable-prefix walk (Rust kernels on the hot path). On top of the engine: role/schema policy projection (forbidden operations are unreachable by construction), a hash-chained replayable audit trail, and checker-guided repair for the provably mask-unenforceable residue.

pip install "grid-guardrail[kernel]"   # kernel extra: Rust mask kernels (5 platforms)

JSON Schema in one call

from grid.jsonschema import compile_json_schema

source, recorded = compile_json_schema(schema)   # -> .grid grammar source
# `recorded` names every constraint present but not mask-enforced (default
# mode records; strict=True refuses instead). Nothing is silently ignored.

Measured on JSONSchemaBench (11,306 real-world schemas, all instance tests, one machine, current engine versions):

engine passing declared false-rejects silent accepts
GRID 0.2.5 10,117 (89.5%) 668 3 502, every one recorded
llguidance 1.7.6 9,487 (83.9%) 1,797 22 0
XGrammar 0.2.3 10,212 (90.3%) 51 427 627

Three philosophies: llguidance refuses what it can't enforce perfectly; XGrammar compiles everything and leaks silently. GRID sits at the frontier: near-best coverage, near-zero false-rejects, and a per-schema record of anything unenforced. Keyword-by-keyword status: grid/jsonschema/SUPPORT.md. The official JSON-Schema-Test-Suite runs in CI under that contract.

Timing note: 0.2.x is the correctness epoch; per-token/compile timings are recorded in the versioned reports but deliberately unoptimized; performance is the 0.3.x epoch. On GRID's home turf (SQL/CFG grammars) the warm-path mask is p50 3.7 µs (see bench/RESULTS.md).

SQL with policy compiled in

import grid
from grid import generate, samplers
from grid.policy.bundle import PolicyBundle
from grid.policy.schema import SchemaSnapshot

model = grid.models.transformers_model.TransformersModel.from_pretrained("gpt2")
g = generate.sql(
    model,
    open("grammars/sql_subset.grid").read(),
    policy=PolicyBundle.from_store({"analyst": {"verbs": ["select"]}}, "analyst"),
    schema=SchemaSnapshot.from_dict({"users": ["id", "name", "email"]}),
    sampler=samplers.multinomial(temperature=0.7),
)
result = g("List all user names", max_tokens=64, seed=42)

Per-role and per-schema grammars make unauthorized verbs, tables, and columns unreachable at decode time; the audit chain reconstructs, bit for bit, what the model was permitted to generate at every step. Decode-time masking is deterministic capability reduction; pair it with an independent check where the SQL executes, both compiled from one policy source.

Guarantees

Soundness, completeness, termination, and near-constant per-token cost are stated with explicit preconditions and paired with empirical tests (tests/, differential against a trial-parse oracle). See DESIGN.md (architecture), GUARDRAIL-REDESIGN.md (design rationale with proofs), LESSONS.md (the measured history), ONBOARDING.md (guided tour).

Development

python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/pytest tests/ -q                       # verification suite
(cd grid_core && maturin develop --release)      # optional Rust kernels
.venv-bench/bin/python bench/compare_engines.py  # cross-engine SQL harness

Benchmark methodology and full reports live in bench/: pinned engine versions, declared runners, full error distributions, no cherry-picking. The design credits the Outlines paper as inspiration; GRID's design and implementation are its own throughout.

License

Apache-2.0. Cite via CITATION.cff (arXiv:2607.11951).

Metadata

Release files for grid-guardrail 0.4.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 grid-guardrail 0.4.0
File Size Uploaded
grid_guardrail-0.4.0.tar.gz 201.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for grid-guardrail 0.4.0
File Interpreter ABI Platform
grid_guardrail-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 421.3 kB

Release files / grid_guardrail-0.4.0.tar.gz

Download URL grid_guardrail-0.4.0.tar.gz
Size 201.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e31199f00377d0415d56558c602b112c163df96b12342e36b80a5b7ecb611534
BLAKE2b-256 checksum
How to use checksums
5e0f5e2ab6931d9bbb1dd1fee535953839514cdb497c02179625a5e45ef35bff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

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 Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release files / grid_guardrail-0.4.0-py3-none-any.whl

Download URL grid_guardrail-0.4.0-py3-none-any.whl
Size 219.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ef187c40f48fdcbc64204e4087f14a770bf2a6c6885846c0c715f75b0521550
BLAKE2b-256 checksum
How to use checksums
e36a5f568a471d3116f0864be91be46fd4d085727ea4de536798e0f82ed91a30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

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 Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.2

2 release files

0.4.1

2 release files

This release

0.4.0 This release

2 release files

0.3.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