Home Knowledge Base Guidance

Guidance is a Microsoft-developed programming language for constraining and controlling LLM outputs with guaranteed structure — replacing probabilistic prompt engineering with deterministic template execution that interleaves generation and computation, ensuring the model produces exactly the format (JSON, XML, code, structured dialogue) your application needs without relying on post-hoc parsing or retry loops.

What Is Guidance?

Why Guidance Matters

Guidance Template Syntax

Basic Constrained Generation:

import guidance
lm = guidance.models.OpenAI("gpt-4")

with guidance.system():
    lm += "You extract information from text."
with guidance.user():
    lm += "Extract the city from: I live in Paris, France."
with guidance.assistant():
    lm += "City: " + guidance.gen("city", stop=".")

Select Directive — forces the model to choose from a fixed list:

lm += "Sentiment: " + guidance.select(["positive", "negative", "neutral"], name="sent")

Regex Constraint — ensures output matches a pattern:

lm += "Date: " + guidance.gen("date", regex=r"d{4}-d{2}-d{2}")

Key Guidance Directives

Guidance vs Alternatives

AspectGuidanceOutlinesInstructorLMQL
Constraint methodTemplate + logitsLogit maskingRetry loopQuery language
Interleaved logicExcellentLimitedNoGood
Local model supportExcellentExcellentAPI onlyGood
JSON schemaGoodExcellentExcellentGood
Learning curveMediumLowLowHigh
Microsoft backingYesNoNoAcademic

Use Cases

Guidance is the deterministic alternative to probabilistic prompt engineering — for applications where structured output is non-negotiable, Guidance replaces fragile "please format as JSON" instructions with guaranteed, token-level constrained generation that eliminates the entire class of output parsing failures.

guidancestructuredmicrosoft

Explore 500+ Semiconductor & AI Topics

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