---
name: "guidance-constrained-grammar"
description: "Enforce strict token-level context-free grammars (CFGs) on model generation."
metadata:
  author: "Guidance"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "constrain generation with guidance"
  - "force regex output llm"
  - "use guidance select choices"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Guidance Context-Free Grammar Constrained Decoding

Controls language model generation tokens using Microsoft Guidance: select() choices, gen() regex constraints, grammar rules, and zero-hallucination structured outputs.

## When to Invoke
Invoke this skill whenever you need to:
- constrain generation with guidance
- force regex output llm
- use guidance select choices

## Execution SOP & Rules
1. Define guidance programs using @guidance decorator functions.
2. Use select(options) to guarantee 100% adherence to allowed categorical values.
3. Constrain string tokens using gen(regex=r'[0-9]{4}-[0-9]{2}-[0-9]{2}') for date formats.
4. Interleave static text templates with generated variables to enforce exact document skeletons.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
