Home Knowledge Base Guidance

Guidance is the constraint-based language model programming framework by Microsoft that enables precise control over LLM output structure through interleaved generation and templating — allowing developers to define exact output formats with variables, conditionals, loops, and regex constraints that the model must follow during generation, eliminating post-processing and reducing hallucination through structural enforcement.

What Is Guidance?

Why Guidance Matters

Core Features

FeatureDescriptionBenefit
TemplatesJinja-style templates with generation blocksStructured output
SelectConstrain output to specific choicesGuaranteed valid enum values
RegexMatch generation against regex patternsFormat enforcement
GenFree-form generation within constraintsControlled creativity
If/ForProgrammatic control flowDynamic output structure

How Guidance Works

Programs are written as templates where `{{gen}} blocks indicate where the model generates text, {{select}}` blocks constrain choices, and Python logic controls flow. The model generates tokens that satisfy all active constraints, producing correctly structured output in a single pass.

Example Patterns

Guidance is the most precise tool for controlling LLM output structure — replacing the unreliability of prompt-based formatting with guaranteed structural compliance through constrained decoding, making it essential for applications where output format correctness is non-negotiable.

guidanceframework

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.