
LMQL
A query language for LLMs that bolts types, templates, and constraints onto prompting.
In short
LMQL is a Python-flavored query language that enforces types and constraints on LLM outputs via an optimizing runtime. It is best for developers building constrained-decoding pipelines who want portable, composable code across multiple model backends.
Pick LMQL if you want a principled, constraint-driven query language for LLMs and are comfortable adopting a small DSL on top of Python.
Skip it if you want a managed platform, drag-and-drop prompt tooling, or a large commercial ecosystem with enterprise support.
LMQL (Language Model Query Language) is an open-source programming language for interacting with large language models, developed by ETH Zurich's Secure, Reliable, and Intelligent Systems Lab. It treats prompting as a first-class programming problem: you write Python-flavored queries with typed variables, control flow, and `where` constraints, and an optimizing runtime enforces those constraints on the model's output (regex, type, length, stop conditions, and more). The result is structured, validated generations without the usual hand-rolled parsing and retry logic.
It's aimed at developers who are tired of stringly-typed prompt engineering and want portable, composable LLM code. LMQL is backend-agnostic, running against OpenAI, Hugging Face Transformers, and llama.cpp with the same query, and it ships nested queries, multi-part prompting, and a `@lmql.query` decorator so calls look like native Python functions. The project is free and open source on GitHub (eth-sri/lmql); there is no hosted SaaS or paid tier.
Because it's a research-led language rather than a commercial product, expect a learning curve, a smaller ecosystem than LangChain or DSPy, and a release cadence tied to academic priorities rather than enterprise SLAs. For anyone building constrained-decoding pipelines or agent loops where output shape matters, it remains one of the more rigorous tools in the category.
LMQL is the rare prompt tool that takes correctness seriously, modeling generation as a constrained search problem instead of string interpolation. It's a sharp pick for engineers who care about structured outputs and portability across model backends, but the DSL tax is real and you're betting on a research project, not a vendor.
— The AI Tool Bible editorial team
Pros
- ✅ Type and regex constraints enforced by the runtime, not after-the-fact parsing
- ✅ Backend-agnostic across OpenAI, HF Transformers, and llama.cpp
- ✅ Nested queries and Python control flow make prompts composable and reusable
- ✅ Fully open source with an academic research pedigree (ETH Zurich SRI Lab)
Cons
- ⚠️ Niche DSL with a real learning curve compared to plain Python + JSON mode
- ⚠️ Smaller community and ecosystem than LangChain, LlamaIndex, or DSPy
- ⚠️ Research-paced development; no commercial support or hosted offering
Use cases
Frequently asked
- What is LMQL and who developed it?
- LMQL is an open-source programming language for interacting with large language models, developed by ETH Zurich's Secure, Reliable, and Intelligent Systems Lab. It treats prompting as a first-class programming problem using typed variables and control flow.
- Which model backends does LMQL support?
- LMQL is backend-agnostic and runs against OpenAI, Hugging Face Transformers, and llama.cpp using the same query. This allows for portable LLM code across different infrastructure.
- How does LMQL handle output validation?
- The optimizing runtime enforces constraints such as regex, type, length, and stop conditions directly on the model's output. This provides structured, validated generations without requiring hand-rolled parsing or retry logic.
- Is LMQL free to use?
- Yes, LMQL is free and open source under an Apache-style license. Users can self-host it or use it with their own model API keys, with no hosted SaaS or paid tier available.
- What are the main limitations of using LMQL?
- LMQL has a learning curve due to its niche DSL and a smaller ecosystem compared to tools like LangChain or DSPy. Development is research-paced with no commercial support or enterprise SLAs.
Explore related
Compare with similar tools
All in Coding →
Cursor
FeaturedAI-first VS Code fork — chat, edit, and agentic coding in one IDE.

GitHub Copilot
FeaturedThe original AI pair programmer, now with chat and agents.

Replit Agent
FeaturedBuild & deploy a full app from a single prompt.

Warp
The agentic development environment, from the terminal up

Cline
Open-source agentic coding assistant that plans, edits, and runs code inside your IDE

Aider
Terminal-based AI pair programmer that writes commits.