LMQL
Language Model Query Language — constrained, efficient prompting with programmatic control over LLM outputs.
About
LMQL (Language Model Query Language) is a programming language and runtime from ETH Zurich's SRI Lab for what its creators call 'language model programming.' Instead of free-form prompting, you write queries with typed variables and where-clause constraints — for example, requiring a generated sentiment label to come from a fixed set, or a summary to be exactly three sentences — and the runtime enforces those constraints during decoding, which is both more reliable and more token-efficient than generate-then-validate loops.
Installable via pip install lmql, it integrates with Python through decorators and supports advanced techniques like prompt sketching (controlled multi-part interactions) and grammar-based constrained generation. It remains a research-grade tool rather than a production framework, but its ideas heavily influenced the constrained-decoding features now appearing across the LLM ecosystem.
What it can do
- Constraint-guided generation with where-clause validation
- Typed prompt variables and template composition
- Efficient constrained decoding (no wasted tokens on invalid outputs)
- Prompt sketching for controlled multi-part LLM interactions
Setup
pip install lmql, then write @lmql.query-decorated Python functions with constraint expressions; works with OpenAI, Hugging Face, and local backends.
Prerequisites
Python 3.8+; access to an LLM backend (API key or local model).
Use cases
Works with
Trust score — 7/10
Scored 7/10 (metrics tier, metrics-v1). Evidence: Verified via vendor site/docs/GitHub and reputable coverage, wave 64; Trending score 68/100 from researcher assessment.
Sources
Every fact above was checked against these sources. Where a claim comes from the provider and couldn't be independently verified, the text says so.