Debuly
Guidance logo

Guidance

Python library for steering language models, combining constrained generation with ordinary control flow so outputs follow regexes, grammars or JSON schemas.

Open source

What is Guidance?

Guidance is an open-source Python library for controlling how a language model produces its output. Instead of hoping a free-form prompt returns the right shape, you write a program that mixes prompt text, Python logic and generation calls. A gen() call can be constrained with a regular expression, select() picks from a fixed list of options, and any context-free grammar can be enforced, so a JSON schema or a Pydantic model becomes a hard constraint on the result. Because a grammar often fixes some tokens in advance, Guidance can insert them itself and skip model forward passes, which the project says reduces latency and cost against conventional prompting. You install it from PyPI with pip install guidance, and it works with backends including Transformers, llama.cpp and OpenAI. Custom building blocks are made with the @guidance decorator, and a Mock model lets you test grammars offline without API calls. The library is free and released under the MIT license.

Use cases

  • Constrain model output with grammars
  • Generate JSON that matches a Pydantic model
  • Mix Python logic with generation
  • Select among fixed options with an LLM
  • Capture generated text into named variables
  • Test grammars offline with a mock model

Who it's for

  • Python developers
  • ML researchers
  • AI engineers
  • Prompt engineers

Why use Guidance

  • Constrained generation makes the output format predictable, which suits parsing JSON or fixed answers.
  • Writing prompts as Python programs lets you use loops, conditionals and tool use alongside generation.
  • Fast-forwarding fixed tokens can cut model passes, which lowers latency and GPU use.
  • It works across local and hosted backends, so the same program can move between models.

Guidance features

  • gen() with regex constraints
  • select() for choosing among fixed options
  • Context-free grammar constraints
  • JSON output from a schema or Pydantic model
  • Custom functions with the @guidance decorator
  • Fast-forwarding of tokens known from the grammar
  • Mock model for offline grammar debugging
  • Jupyter notebook widget for richer output
  • Backends including Transformers, llama.cpp and OpenAI

Guidance integrations

  • Transformers
  • llama.cpp
  • OpenAI
  • Pydantic
  • Jupyter

How to get started with Guidance

  1. Install it with pip install guidance, along with the backend your model needs.
  2. Load a model object such as Transformers("microsoft/Phi-4-mini-instruct") or a llama.cpp model.
  3. Build the conversation with system(), user() and assistant() blocks and append text to the model object.
  4. Add gen() or select() calls with a regex, a grammar or a JSON schema to constrain the output.
  5. Read results back by name, such as lm["lm_response"], and test grammars with the Mock model.

Guidance limitations

  • A library for developers, not an end-user app
  • Full grammar constraints need a backend model with full support for Guidance
  • Its programming style has a learning curve compared with plain prompting

Guidance pricing

Guidance is open source, so you can use and self-host it for free.

Prices can change and may vary by country or exclude tax. Check the official pricing page.

Guidance alternatives

The main Guidance alternatives listed on Debuly are Outlines, BAML, Instructor, LMQL, TypeChat and Chroma. The table compares pricing and platforms; order is A–Z.

Guidance compared with its alternatives
ToolPricingStarting pricePlatforms
GuidanceOpen source—API
BAMLOpen source—CLI, macOS, Linux, Windows
ChromaOpen source$250/moAPI, CLI, Self-hosted, Web
InstructorOpen source—API, Self-hosted
LMQLOpen source—Python, CLI, Web, Self-hosted
OutlinesOpen source—API
TypeChatOpen source——
  1. BAML

    Open-source, TypeScript-like programming language for agents, with typed LLM functions, built-in tests and SDK generation.

  2. Chroma

    Open-source search database for AI apps, with vector, full-text, regex and metadata search and a serverless cloud option.

  3. Instructor

    Open-source library that gets validated, typed structured data out of LLMs using Pydantic models and automatic retries.

  4. LMQL

    Programming language from ETH Zurich for LLM prompting that adds Python control flow, typed variables and hard output constraints.

  5. Outlines

    Python library from .txt that makes LLM output match a type you define, such as a Pydantic model, enum or regex, during generation.

  6. TypeChat

    Microsoft library that builds natural-language interfaces by using your own types to define what a model must return.

Guidance FAQ

Is Guidance free?

Yes. The library is released under the MIT license and installs from PyPI. No paid plans are listed, though a hosted model backend may charge for its own use.

Which models does Guidance work with?

The README says it supports a variety of backends, including Transformers, llama.cpp and OpenAI. Full grammar constraints depend on the backend having full support for Guidance.

Can Guidance produce JSON?

Yes. A JSON schema is a context-free grammar, so gen_json can constrain a model to a schema or Pydantic model and the result can be loaded with json.loads or validated by Pydantic.

How do I install Guidance?

Run pip install guidance. If you already have the backend your model needs, no extra setup is described.

Who is Guidance for?

Developers and researchers who need predictable, structured output from language models, particularly those who prefer writing Python to long prompts.

What are alternatives to Guidance?

Alternatives include Outlines, BAML, Instructor and LMQL, which also help produce structured LLM output.

Sources & verification

Facts on this page come from the official sources below, each with the date we read it. Written by Debuly; the vendor did not review this page.

SourceTypeAccessed
github.com/guidance-ai/guidanceofficial

Image credits

  • Logo: from avatars.githubusercontent.com · fetched · Vendor trademark, used only to identify the product; removed on request
  • Cover: none collected yet, so a generated tile is shown.

Spot an error? Report an issue with this listing. We also remove a logo or image on the owner's request.