Skip to content

arch: constrained generation (xgrammar-style) for LLM-driven CLIF/DSL authoring #116

Description

@elasticdotventures

Summary

Distinct from (and complementary to) the gateway policy gate shipped 2026-07-25 (crates/ledgerr-mcp/src/gateway_policy.rs), which checks tool calls after an LLM emits them. This issue is about constrained generation in the inference sense: forcing an LLM's token generation to conform to a formal grammar (e.g. via xgrammar or similar grammar-constrained decoding) so that syntactically invalid or out-of-vocabulary CLIF/DSL output is structurally impossible to produce, not just caught after the fact.

Context

  • Term clarified by the operator 2026-07-25: "constrained generation," not "constraint generation" — this is the xgrammar/grammar-constrained-decoding layer at LLM inference time.
  • ledgrrr already has a local-model story to hook this into: crates/ledgerr-host has local-llm/mistralrs-llm features (Phi-4 GGUF), and the Justfile has windows-ai-* recipes for Microsoft Foundry Local. PRD-10's desktop-agent controller also has a "local CPU model runtime" slot that's currently configured: false (crates/ledgerr-desktop-agent/src/status.rs).
  • Depends on the CLIF AST / grammar work (see companion issue) existing first — you need a formal grammar to constrain against before you can wire constrained decoding to it.

Scope (not yet designed)

  • Which local inference runtime(s) this needs to integrate with (mistralrs, Foundry Local, others) and whether each has/needs grammar-constrained decoding support.
  • Whether the constraint grammar is derived automatically from the CLIF AST (Rust types → grammar) or hand-maintained in parallel.
  • Where this sits relative to the gateway policy gate — likely front-loads correctness (LLM literally cannot emit invalid CLIF), with the gateway gate remaining as defense-in-depth for any non-constrained client (e.g. Claude Desktop via MCP, which isn't running through ledgrrr's own local inference stack).

Related

  • Roadmap: docs/superpowers/plans/2026-07-25-ledgrrr-integration-roadmap.md, subsystem 5.
  • Companion issues: CLIF AST/interpreter, RDF/triple-store knowledge graph.

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureArchitectural design decisionsresearchResearch spike or investigation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions