# eth-sri/lmql

A language for constraint-guided and efficient LLM programming.

Repository: https://github.com/eth-sri/lmql
Canonical: https://ross.abutalabs.com/products/lmql
Homepage: https://lmql.ai
Language: Python
License: Apache-2.0
License Family: permissive
Topics: chatgpt, huggingface, language-model, programming-language
Last push: 2025-05-22T07:32:31+00:00

## Health v2 (maintenance only)
Score: 32/100 (v2, computed 2026-09-02T17:46:02.011165+00:00)
- activity 22, release rhythm 8, longevity 98
- inputs: {"age_days": 1378, "days_push": 468, "days_rel": null, "gap_med": null, "n_releases_24m": 0}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 4208, forks 221 (observed 2026-08-28T04:08:39.062590+00:00)

## What it is
LMQL is a query/programming language for large language models, implemented as a Python-based superset that lets developers interleave prompts, control flow, and constraints in normal code. It supports multiple inference backends (OpenAI, HuggingFace Transformers, llama.cpp) with an optimizing runtime that enforces constraints during generation.

## Use cases
- write llm programs with constraints on generated output
- constrain llm responses to a format or length
- build multi-step prompting pipelines with control flow
- run the same prompt code across openai and local models
- serve a local huggingface or llama.cpp model for prompting
- modularize reusable prompt components with nested queries

## When to choose
- you need token-level constraints or typed outputs from an llm
- you want portable prompt programs across multiple model backends
- you prefer declarative prompting embedded in python code

## When to avoid
- you only need simple one-off api calls to a chat model
- you rely heavily on chat-only apis with limited constraint support
- you need a production framework with agents and tooling beyond prompting

## Facets
- artifact type: library
- maturity: active
- function: programming-language, llm-inference, prompt-engineering, sdk, cli
- domain: large-language-models, programming-languages, artificial-intelligence, developer-tools
- platform: python, cli, cross-platform
- tags: dsl, constrained-decoding, llm-prompting, llama-cpp, openai, huggingface-transformers, query-language, natural-language-processing, gpu

## Member repositories
- eth-sri/lmql (main) score 32

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:08:39.062590+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-29T18:22:30.573583+00:00, confidence not recorded.
  - readme: https://github.com/eth-sri/lmql (fetched 2026-08-28T04:08:39.062590+00:00, sha 490f2188debc)
  - homepage: https://lmql.ai (fetched 2026-08-29T09:12:47.800149+00:00, sha cfb312c99dab)
  - site_page: https://lmql.ai/docs (fetched 2026-08-29T09:12:47.809450+00:00, sha 0c275d9601ca)
  - site_page: https://lmql.ai/docs/language/nestedqueries.html (fetched 2026-08-29T09:12:47.811750+00:00, sha 270dfbb09e93)
  - site_page: https://lmql.ai/docs/models/llama.cpp.html (fetched 2026-08-29T09:12:47.813574+00:00, sha 9496f989bf8f)
  - site_page: https://lmql.ai/docs/models/openai.html (fetched 2026-08-29T09:12:47.815085+00:00, sha cd942c35ec67)
  - site_page: https://lmql.ai/docs/models/hf.html (fetched 2026-08-29T09:12:47.816772+00:00, sha 2b9c89085a13)
- Data as of 2026-08-30T08:39:29.467469+00:00.
