Description
LMQL is a programming language for working with large language models, developed by the SRI Lab at ETH Zurich and contributors. A query is written as a Python function whose body mixes ordinary Python with prompt text. Variables inside the prompt are filled in by the model, and you can constrain them with a where clause, for example to limit length or stop at a character, or give them a type such as int or a regular expression so the output has a guaranteed format. The query returns its results as ordinary Python values, so it can be called like any other function. The same query can run against several backends, including llama.cpp, OpenAI and Hugging Face Transformers, with a single line of code to switch between them. Recent versions added nested queries, which let you reuse prompt components, and the project also includes a browser playground and an execution trace view for debugging the flow.…
Highlights
- Prompts written inside Python functions
- Constraints and typed variables for model output
- Same query runs on llama.cpp, OpenAI or Transformers
- Nested queries for reusable prompt parts
- Execution trace and browser playground
Ratings & Reviews
No ratings yet
Be the first to rate LMQL.
People also visit
LMQL FAQ
What is LMQL?
A query language and runtime for prompting large language models, where prompts, constraints and output types are written in a Python-style syntax.
Who is it for?
Developers building applications on language models who want structured, constrained and reusable prompts with debugging support.
Which models can it use?
The site lists llama.cpp, OpenAI and Hugging Face Transformers as backends, and says you can switch between them with one line of code.
How do I constrain the output?
Use a where clause, for example to limit the length of a variable or stop generation at a given string, or declare a typed variable such as int or a regular expression.
Can I try it without installing anything?
The site has a playground where you can run LMQL queries in the browser.
What are nested queries?
A recent feature that lets one query call others, so local instructions and prompt components can be reused in several places.
How do I call a query from Python?
A query is a normal Python function, so you call it like any other function and it returns the values it produces.
What are the best LMQL alternatives?
Popular alternatives to LMQL include Langtrace, Appl and liter-llm. See all LMQL alternatives
