Guidance

Microsoft's framework for controlling language model generation

open-sourceproductionpythonmicrosoftprompt-engineeringopen-sourcestructured-outputs

Memory Types

Integrations

openai, azure, transformers, llamacpp


Overview


Guidance is Microsoft's framework for controlling and steering language model generation. It provides a templating language that interleaves generation with control flow, allowing precise specification of output structure while maintaining natural language fluency. Guidance is particularly powerful for complex prompts that mix structured and unstructured outputs.


The framework enables developers to constrain generation at the token level, ensuring outputs follow specific patterns without post-processing. This makes it ideal for applications requiring both creative generation and structural constraints, like code generation, form filling, or interactive agents.


Key Features


  • **Handlebars-Like Syntax**: Familiar templating with control flow
  • **Token-Level Control**: Constrain generation at token level
  • **Stateful Generation**: Maintain state across generation steps
  • **Role-Based Chat**: Structured multi-turn conversations
  • **Regex Constraints**: Pattern-based output control
  • **Tool Integration**: Easy integration of Python functions
  • **Caching**: Intelligent prompt caching for efficiency
  • **Multiple Backends**: OpenAI, Azure, Transformers, llama.cpp

  • When to Use Guidance


    Guidance is ideal for:

  • Complex prompts mixing structure and creativity
  • Multi-step generation with intermediate validation
  • Applications requiring precise output control
  • Code generation with specific patterns
  • Interactive agents with structured dialogs
  • Projects on Microsoft Azure stack

  • Pros


  • Powerful control over generation process
  • More efficient than retry-based validation
  • Works with both cloud and local models
  • Microsoft backing and support
  • Good for complex, multi-step prompts
  • Intelligent caching reduces costs
  • Strong for code generation use cases
  • Open-source and well-maintained

  • Cons


  • Steeper learning curve than simpler tools
  • Template syntax can become complex
  • Less intuitive than Python-native approaches
  • Smaller community than LangChain
  • Documentation could be more comprehensive
  • Some features specific to Microsoft ecosystem
  • Can be overkill for simple use cases

  • Pricing


  • **Open Source**: Free, MIT license
  • **Azure Integration**: Azure OpenAI costs apply
  • **Self-Hosted**: Free to use anywhere