Context-free grammar for structured generation.
If provided, Outlines will generate text that adheres to the specified grammar. The grammar should be defined in EBNF format.
This can be useful for generating structured outputs like mathematical expressions, programming languages, or custom domain-specific languages.
Example:
grammar = ''' ?start: expression ?expression: term (("+" | "-") term)* ?term: factor (("" | "/") factor) ?factor: NUMBER | "-" factor | "(" expression ")" %import common.NUMBER '''
Note: Grammar-based generation is currently experimental and may have performance limitations. It uses greedy generation to mitigate these issues.
For more details and examples, see: https://dottxt-ai.github.io/outlines/reference/generation/cfg/