LMQL
FreeLMQL is a query language for large language models.
About LMQL
LMQL is a programming language specifically designed for interacting with large language models (LLMs). It enables robust and modular prompting by incorporating types, templates, constraints, and an optimizing runtime. With LMQL, users can write expressive, multi-part prompts using Python control flow and string interpolation, enforce hard constraints on model output (such as length, stop tokens, and data types), and easily switch between multiple backends like llama.cpp, OpenAI, and Hugging Face Transformers. The language also supports advanced features like nested queries for modular instructions, tool augmentation, chatbot development, and meta prompting. LMQL is developed by the SRI Lab at ETH Zurich and is available as open source.
Key Features
Pros & Cons
- Robust and modular prompting with type safety and constraints
- Guaranteed output format through hard constraints
- Deep Python integration for expressive programmatic prompts
- Portable across multiple LLM backends with a single line of code change
- Open source and free to use
- Requires learning a new programming language/syntax specific to LMQL
- May have a steeper learning curve compared to simpler prompting frameworks