Building with AI

Guidance

Quick explainer2 min readAdvanced

Guidance is an open-source Python library for controlling language models, mixing ordinary code with generation and constraining output with rules such as regular expressions and grammars.

In plain words

With plain prompting you send text and hope the reply has the right shape. Guidance lets you write a program where fixed text, Python logic such as loops and conditions, tool calls and model generation are interleaved. Where you add constraints, the output must match them. Because a format often fixes some tokens in advance, Guidance can skip generating those, which can lower latency and cost.

A quick example

Imagine you need the model to output JSON with a fixed set of keys. The braces, key names and quotes are already known, so Guidance inserts them directly and only asks the model to generate the values, each constrained to the allowed pattern.

Where you'll meet it

  • Getting reliably formatted output from models.
  • Local models run through Transformers or llama.cpp.

Related

Sources

  1. Docsguidance-ai/guidance, Guidance (GitHub) · read 29 Sept 2026
  2. DocsGuidance: control LM output, Microsoft Research · read 29 Sept 2026

Checked by WhatIsAI against the sources above · 29 Sept 2026. Spotted an error? Report it.