guidance

Generate valid JSON, XML, code, and structured data using regex constraints and grammars.

Updated Jun 26, 2026
One-click install
npx skills add https://github.com/NITISH-gitbit/hermes-custom --skill guidance-nitish-gitbit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/NITISH-gitbit/hermes-custom/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/NITISH-gitbit/hermes-custom --skill guidance-nitish-gitbit

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires guidance, transformers, llama.cpp, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

This Skill helps you control and enforce the output of language models, ensuring they generate valid JSON, XML, code, and structured data, and build complex workflows with Pythonic control flow.

Core Features & Use Cases

  • Constrained Generation: Use regex and grammars to ensure valid JSON, XML, code, and structured data generation.
  • Structured Output: Generate outputs with structured formats (dates, emails, IDs, etc.).
  • Multi-Step Workflows: Build complex workflows with Pythonic control flow and structured output constraints.
  • Use Case: Create a multi-step workflow to extract data from a JSON document, validate it, and then transform it into XML format.

Quick Start

Use the guidance skill with the 'extract_json_to_xml' command to convert a JSON document to XML format.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I force an LLM to generate valid JSON and XML outputs?

You can constrain LLM output to valid JSON and XML using regex constraints and grammars. This enforces structured generation by restricting the model's output space to specific syntax patterns during decoding.

How do I build multi-step workflows with Pythonic control flow for LLM generation?

Build multi-step workflows with Pythonic control flow and structured output constraints to chain LLM calls. This allows you to extract data from a JSON document, validate it, and then transform it into XML format sequentially.

Do I need Hugging Face transformers or llama.cpp to enforce structured output?

You need the guidance library to enforce structured output, with optional support for transformer backends like Hugging Face models or llama.cpp. These backends provide the underlying model inference for the constrained generation framework.

What is the best way to generate structured data like dates and emails using LLMs?

The best way to generate structured data like dates and emails is by applying structured output constraints with regex. This guarantees the language model formats specific data types exactly as required without parsing errors.

Does constrained generation with regex grammars work for automated code generation?

Yes, constrained generation applies to automated code generation by using regex and grammars to enforce syntax rules. This ensures the LLM generates valid code snippets that conform to specific language constraints.

Why does my LLM output invalid structured data instead of the required format?

LLM outputs become invalid without constrained generation. Applying regex constraints and grammars during decoding forces the model to follow exact syntax rules, preventing malformed structured data and format violations.