Outlines is a library designed to ensure machine-readable output from generative models by applying programmatic constraints during the token sampling process. It functions as a toolkit for forcing large language models to generate text that strictly adheres to JSON schemas, regular expressions, and formal grammars, enabling the integration of model responses into existing software systems.
The library distinguishes itself by integrating formal language rules directly into the sampling loop. It achieves this by converting regular expressions into deterministic finite automata and utilizing logit-based token masking to restrict the model's next-token probability distribution. By tracking the state of a formal grammar and filtering the vocabulary through a prefix tree, the system ensures that every generated sequence conforms to a predefined structural specification.
Beyond core generation, the framework provides capabilities for auditing schema compliance to verify data structures against defined rules. This approach supports the design of predictable pipelines where model outputs are guaranteed to be consistent and formatted for downstream parsing. The library is available as a Python package for integration into generative AI workflows.