LMQL
A query language for LLMs that bolts types, templates, and constraints onto prompting.
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
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.
Aider
Terminal-based AI pair programmer that writes commits.
Codeium
Free, fast AI autocomplete + chat across 70+ editors.
Cody
Sourcegraph's AI coding assistant — codebase-aware via their search index.