maskforge-core
Schema-guided token masks for reliable structured generation in Rust. The crate compiles JSON Schema and regular expressions into reusable executables, binds them to exact tokenizer bytes, and produces a packed allowed-token bitmask at every decoding step.
This crate has no PyO3 dependency and links standalone; the Python bindings live in the
separate maskforge-py crate. See the repository README
for the full project overview, verified model output, current JSON Schema support, and installation
instructions for both Rust and Python.
See the public architecture, JSON Schema support, and development roadmap for details.
use Arc;
use ;
let mut token_map = default;
for byte in 0u8..=u8MAX
let eos_token_id = 256;
let schema_text = r#"{"type":"boolean"}"#;
let token_id = try_from?;
let vocabulary = try_from?;
let compiler = new;
let program = compiler.compile_json_schema?; // vocabulary-independent, reusable
let bound = program.bind?; // picks regular or structured internally
let mut session = bound.start_session?;
let mut mask = vec!;
session.write_mask?;
session.advance?;
The complete runnable version is in examples/basic_json_schema.rs. Compiler owns a configurable,
clearable executable cache. SchemaProgram, CompiledVocabulary, and BoundSchema are immutable
and reusable; each generated sequence owns one mutable Session.
License
Apache-2.0. Portions derive from outlines-core
(also Apache-2.0); see PROVENANCE.md for the file-by-file audit trail.