lmql-constraints

Generate structured LLM outputs with LMQL grammar and logical constraints.

1|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/HermeticOrmus/hermetic-claude --skill lmql-constraints-hermeticormus
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: lmql-constraints
Source: https://github.com/HermeticOrmus/hermetic-claude/tree/main/claude/skills/lmql-constraints
Command: npx skills add https://github.com/HermeticOrmus/hermetic-claude --skill lmql-constraints-hermeticormus

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill enables the creation of LLM outputs that are guaranteed to conform to specific grammatical structures, logical conditions, and type constraints, ensuring reliable and predictable AI-generated content.

Core Features & Use Cases

  • Constrained Decoding: Enforces grammar and logic on LLM outputs.
  • Type-Safe Prompting: Integrates with Python type hints and Pydantic models for structured data generation.
  • Use Case: Generate JSON objects from an LLM that strictly adhere to a predefined schema, or ensure a generated summary is exactly three sentences long.

Quick Start

Use the lmql-constraints skill to generate a JSON object with 'name', 'age', and 'city' fields, ensuring the age is a valid integer.

Frequently Asked Questions about lmql-constraints

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce JSON schema compliance during LLM generation?

To enforce JSON schema compliance during LLM generation, you can use constrained decoding to apply grammar and logical conditions, guaranteeing the LLM output strictly adheres to your predefined type constraints.

What is type-safe prompt engineering for structured outputs?

Type-safe prompt engineering uses a domain-specific language to define categorical structures, variables, and token distributions, ensuring LLM outputs reliably conform to specific grammatical structures and logical conditions.

Can I use Python type hints and Pydantic models to constrain LLM outputs?

Yes, type-safe prompting integrates directly with Python type hints and Pydantic models, allowing you to generate structured data objects like JSON with guaranteed format compliance and valid field types.

How do I force an LLM to generate exactly three sentences for a summary?

You can force an LLM to generate exactly three sentences by applying constrained decoding with logical operators, restricting the token generation sequence to match your specific length and grammatical conditions.

What are the limitations of constrained decoding for prompt engineering?

Constrained decoding requires defining explicit grammar and logical conditions in a DSL, meaning it is limited to outputs where format and type constraints can be deterministically specified and enforced over token sequences.

Does LMQL work with predefined categorical structures for text generation?

Yes, LMQL utilizes a DSL for defining categorical structures, variables, and distributions over token sequences, enabling type-safe prompt templates that produce reliable and predictable AI-generated content.