← AI GitHub

AI GitHub

LMQL for studying constrained LLM programs

Experiment with a query language that puts model calls and constraints in the same program.

Language ModelsPublished 2 min read

Key Takeaways

  • LMQL combines prompt fragments, generated variables and constraints in a Python-like query.
  • Use a documented backend and pin dependencies for a reproduction.
  • Open a small query in the documented environment and constrain one variable to an enumerated choice.
  • Treat backend compatibility as part of the experiment.

How it works

LMQL combines prompt fragments, generated variables and constraints in a Python-like query. Its research implementation illustrates how constraints can be checked during generation rather than after the complete response.

What you need

Use a documented backend and pin dependencies for a reproduction. The query language is most informative when you can inspect how a specific constraint changes model generation.

What to try first

Open a small query in the documented environment and constrain one variable to an enumerated choice. Change the constraint and see which output choices the runtime permits.

Compare a query that stops early with one that reaches its output limit. The difference helps separate constraint behavior from truncation in the generation backend.

Where to look for failures

Treat backend compatibility as part of the experiment. Some research examples refer to older model APIs, so verify the model and runtime combination before adapting them.

Related Franklin pages

Use a constraint that permits several valid outputs. That makes it easier to inspect how each programming model represents choices and where it enforces them.

For the distinction between requesting structured output and enforcing its format, see Franklin’s glossary. Structured output

Project documentation

Try it for your workflow

Explore the project’s documentation for setup and usage, or save this page to a collection for later.

Read the project documentation ↗