api.video is a video API for uploading, encoding, hosting and live streaming video, with AI transcription and summaries.
LMQL
Programming language from ETH Zurich for LLM prompting that adds Python control flow, typed variables and hard output constraints.
What is LMQL?
LMQL is a programming language for talking to large language models, created by the SRI Lab at ETH Zurich and contributors. A query is written like a Python function: top-level strings are prompts, square-bracket variables such as [ANSWER] mark where the model generates text, and a where clause sets hard constraints that the runtime enforces, for example a length limit, a stop phrase, a set of allowed values, a regex or a type like int. Because queries use ordinary loops, string interpolation and nested queries, prompts become modular programs, and the results come back as plain Python variables. Typed output and dataclasses give schema-safe JSON, and Python functions can be exposed to the model as tools. LMQL runs across backends including OpenAI models, local Hugging Face Transformers models and llama.cpp. It installs with pip, has a browser Playground IDE and a CLI, and is open source with no listed pricing.
Use cases
- Constrain LLM output with a where clause
- Generate schema-safe JSON from a model
- Write multi-step prompts with Python control flow
- Expose Python functions as model tools
- Extract typed values from model responses
- Build reusable prompts with nested queries
- Prototype prompts in the Playground IDE
Who it's for
Why use LMQL
- Hard constraints keep output within a length, set of values, regex or type, instead of relying on the model to follow instructions.
- Typed variables return results as normal Python objects, so downstream code needs less parsing.
- The same query can run on different backends by changing one line.
- Nested queries let you split complex prompts into reusable pieces.
- The Playground shows the decoding graph, which helps you see how a query was executed.
LMQL features
- Constraints on generation with a where clause
- Typed variables such as int and dataclasses for structured output
- Regex constraints on generated text
- Python loops and string interpolation inside prompts
- Nested queries for modular, reusable prompt pieces
- Tool use by exposing Python functions to the model
- Switch between model backends with one line
- Browser-based Playground IDE with a decoding graph view
- Command-line tool, lmql run, for .lmql files
- Query functions callable from Python with the lmql.query decorator
LMQL integrations
How to get started with LMQL
- Install LMQL with pip in a Python 3.10 or newer environment, adding the hf extra for local GPU models.
- Set OPENAI_API_KEY or an api.env file if you plan to use OpenAI models.
- Write a query: prompt strings, [VARIABLES] for generation and a where clause for constraints.
- Run it in the Playground with lmql playground, from a .lmql file with lmql run, or as a Python function.
- Read the generated variables as Python values and chain further queries or tools.
LMQL limitations
- Constraint support is partial on OpenAI Chat API models, which limits what the runtime can enforce
- You need to learn the query syntax
- Local Transformers models need an inference server started with lmql serve-model
- The Playground needs Node.js installed
LMQL pricing
LMQL is open source, so you can use and self-host it for free.
Prices can change and may vary by country or exclude tax. Check the official pricing page.
LMQL alternatives
The main LMQL alternatives listed on Debuly are Guidance, Outlines, Instructor, Pydantic AI, LangChain and BAML. The table compares pricing and platforms; order is A–Z.
| Tool | Pricing | Starting price | Platforms |
|---|---|---|---|
| LMQL | Open source | — | Python, CLI, Web, Self-hosted |
| BAML | Open source | — | CLI, macOS, Linux, Windows |
| Guidance | Open source | — | API |
| Instructor | Open source | — | API, Self-hosted |
| LangChain | Freemium | $39/mo | Web, API, Self-hosted |
| Outlines | Open source | — | API |
| Pydantic AI | Open source | — | API, CLI, Self-hosted |

BAML
Open-source, TypeScript-like programming language for agents, with typed LLM functions, built-in tests and SDK generation.
Open sourceVisit BAML (official site)
Guidance
Python library for steering language models, combining constrained generation with ordinary control flow so outputs follow regexes, grammars or JSON schemas.
Open sourceVisit Guidance (official site)
Instructor
Open-source library that gets validated, typed structured data out of LLMs using Pydantic models and automatic retries.
Open sourceVisit Instructor (official site)
LangChain
Open-source framework for building LLM agents, paired with LangSmith for tracing, evals and agent deployment.
FreemiumVisit LangChain (official site)
Outlines
Python library from .txt that makes LLM output match a type you define, such as a Pydantic model, enum or regex, during generation.
Open sourceVisit Outlines (official site)
Pydantic AI
A type-safe, model-agnostic Python framework for building agents and LLM applications, from the team behind Pydantic.
Open sourceVisit Pydantic AI (official site)
LMQL FAQ
Is LMQL free?
LMQL is open source and installs with pip. The site lists no plans or prices; the pricing page returns a not-found error. You pay only for any model API you call, such as OpenAI.
Which models does LMQL support?
It works across backends including OpenAI Completions and Chat models, Azure OpenAI, local Hugging Face Transformers models and llama.cpp. Chat API models offer only partial constraint support.
Does LMQL work with LangChain and LlamaIndex?
Yes. The docs list integrations that let you use LangChain retrievers in LMQL and LMQL inside LangChain pipelines, and build retrieval loops with LlamaIndex. Output can also be processed as Pandas DataFrames.
How do I run LMQL?
Install it with pip install lmql, then use the browser Playground via lmql playground, the lmql run command for .lmql files, or import the lmql package in Python.
Can LMQL produce structured JSON?
Yes. Typed variables and dataclasses let you generate schema-safe data that returns as Python objects, and template-based queries can produce JSON.
What are alternatives to LMQL?
Alternatives for structured and constrained generation include Guidance, Outlines, Instructor, PydanticAI and LangChain, which differ in how much they rely on a custom language versus Python libraries.
Sources & verification
Facts on this page come from the official sources below, each with the date we read it. Written by Debuly; the vendor did not review this page.
| Source | Type | Accessed |
|---|---|---|
| lmql.ai/ | official | |
| lmql.ai/pricing | pricing | |
| lmql.ai/playground/ | official | |
| lmql.ai/docs/installation.html | docs | |
| lmql.ai/docs/latest/lib/integrations.html | docs | |
| lmql.ai/docs/latest/models/openai.html | docs |
Image credits
- Logo: none collected yet, so a monogram is shown.
- Cover: none collected yet, so a generated tile is shown.
Spot an error? Report an issue with this listing. We also remove a logo or image on the owner's request.



