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.3.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.3.0
File Size Uploaded
grid_guardrail-0.3.0.tar.gz 151.3 kB Details

Built distribution (wheel)

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

Total release size: 319.8 kB

Release files / grid_guardrail-0.3.0.tar.gz

Download URL grid_guardrail-0.3.0.tar.gz
Size 151.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f5ead90d8c8c7b1c0df8a40fc44632878ac10f05f42ed5f783bfbe056baa07e3
BLAKE2b-256 checksum
How to use checksums
a996c76ffe8d50b31f7a0c41d0178680f46ccb2f25918d20337b4fa5f91bb580
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 29, 2026.

Transparency log

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

Download URL grid_guardrail-0.3.0-py3-none-any.whl
Size 168.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e34969f6535540e4e8f0a3ec1900b62de50021b2f8b4d21a6aaa1d831d390c87
BLAKE2b-256 checksum
How to use checksums
7de390827553db3221da8b1b79e858aca7caa2f57153fdd062b29aef3339d7b2
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 29, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

This release

0.3.0 This release

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