guidance-grammars

Generate grammar-constrained LLM outputs using Microsoft's Guidance library.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the challenge of generating structured and predictable output from Large Language Models (LLMs) by enforcing grammar constraints. It ensures that LLM outputs conform to specific formats, types, and rules, making them more reliable for programmatic use.

Core Features & Use Cases

  • Grammar-Constrained Generation: Use regular or context-free grammars to guide LLM output.
  • Structured Outputs: Generate outputs that are guaranteed to be in a specific format (e.g., JSON, specific text patterns).
  • Type-Safe Prompting: Build complex generation pipelines with interleaved computation and constrained generation.
  • Use Case: Automatically generate valid JSON objects from an LLM for API requests, ensuring the output is always parsable and adheres to a predefined schema.

Quick Start

Use the guidance-grammars skill to generate a JSON object representing a user profile with name and email fields.

Frequently Asked Questions about guidance-grammars

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

FAQPage Schema
How do I force an LLM to generate valid JSON output?

You can force an LLM to generate valid JSON output by applying grammar-constrained generation to enforce specific formats and types. This ensures LLM outputs conform to a predefined schema, making them reliable for programmatic use.

What is grammar-constrained generation for LLMs?

Grammar-constrained generation for LLMs uses regular or context-free grammars to guide output. It enforces specific rules and formats, creating type-safe prompt templates for deterministic LLM responses.

How do I build type-safe prompt templates for structured outputs?

Build type-safe prompt templates for structured outputs by using categorical grammar mapping with sequential composition, selection, and capture primitives. This facilitates interleaved computation and constrained generation to guarantee specific formats.

Does Microsoft's Guidance library support context-free grammars for LLM prompting?

Yes, Microsoft's Guidance library supports context-free grammars for LLM prompting. It enables grammar-constrained generation using categorical grammar mapping, allowing complex generation pipelines with deterministic responses.

Why does my LLM output fail API requests due to formatting errors?

LLM output fails API requests due to formatting errors when it lacks grammar constraints. Enforcing grammar rules automatically generates valid objects that are always parsable and adhere to a predefined schema.