xgrammar

Grammar()

This class represents a grammar object in XGrammar, and can be used later in the grammar-guided generation.

GrammarCompiler(tokenizer_info, *[, ...])

The compiler for grammars.

CompiledGrammar()

This is the primary object to store compiled grammar.

GrammarMatcher(compiled_grammar, *[, ...])

Match the output of the LLM to the specified grammar, then generate the mask for the next token.

TokenizerInfo(encoded_vocab[, vocab_type, ...])

The tokenizer info contains the vocabulary, the type of the vocabulary, and necessary information for the grammar-guided generation.

VocabType(value[, names, module, qualname, ...])

The type of the vocabulary.