guidance

Constrain LLM outputs with regex and CFG grammar constraints.

31|3|Updated May 7, 2026
One-click install
npx skills add https://github.com/markwang2658/hermes-windows-native --skill guidance-markwang2658
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/markwang2658/hermes-windows-native/tree/main/hermes-agent/optional-skills/mlops/guidance
Command: npx skills add https://github.com/markwang2658/hermes-windows-native --skill guidance-markwang2658

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill helps engineers enforce structured, reliable outputs from large language models by applying regex constraints and grammars, ensuring formats like JSON, XML, and code are valid and consistent.

Core Features & Use Cases

  • Regex and grammar-based constrained generation to guarantee valid, structured outputs.
  • Token healing, grammar-based generation, and context-manager orchestration to build multi-step workflows.
  • Pythonic guidance functions to compose reusable generation patterns and tool-assisted prompts.

Quick Start

Ask the AI to generate a validated JSON object using regex and grammar constraints.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I constrain LLM outputs to guarantee valid JSON and XML formats?

Regex and grammar constraints enforce valid JSON and XML generation by restricting token selection to only syntactically correct sequences. This approach guarantees structured outputs without relying on post-generation validation or retry logic.

What is token healing and how does it fix constrained generation artifacts?

Token healing is a technique that automatically fixes boundary token artifacts during constrained generation. It adjusts the prompt's final token to ensure smooth regex and grammar enforcement without breaking the intended text format.

How do I build multi-step LLM workflows with reusable generation patterns?

You can build multi-step LLM workflows using Pythonic context managers and functions to orchestrate grammar constraints and tool-assisted prompts. This allows you to compose reusable generation patterns across diverse backends and local models for complex tasks.

Can I use regex and CFG grammar constraints with local models?

Yes, regex and CFG grammar constraints are supported with multiple backends, including local models. This allows you to enforce structured, valid results directly on local hardware without relying on external API providers.

What is the best way to prevent LLMs from generating invalid code syntax?

The best way to prevent invalid code syntax is applying context-free grammar constraints during inference. This restricts the LLM to only generate valid code structures, eliminating syntax errors before they occur.