Skip to main content

Crate xgrammar

Crate xgrammar 

Source
Expand description

Safe, idiomatic Rust bindings for the xgrammar C++ library for constrained decoding of large language models.

This crate wraps xgrammar’s grammar compilation and token-level matching so you can drive constrained generation (JSON schema, regex, BNF, structural tags) from Rust while retaining the performance of the upstream C++ implementation.

§Highlights

See each item’s documentation for usage details, including when a BatchGrammarMatcher instance is required vs when associated functions can be called directly.

Re-exports§

pub use tokenizers;

Modules§

huggingface_hub

Structs§

BatchGrammarMatcher
CompiledGrammar
Grammar
GrammarCompiler
GrammarMatcher
MetadataFromHF
TokenizerInfo

Enums§

VocabType
XGrammarErr

Statics§

EOS_TOKEN_ID_KEY
GENERATION_CONFIG_FILE
HF_CONFIG_FILE
TOKENIZER_ALLOW_PATTERN
TOKENIZER_CONFIG_FILE
TOKENIZER_FILE
TOKENIZER_MODEL_KEY
TOKENIZER_VOCAB_KEY

Type Aliases§

TokenId
VocabMap