explaingit

guidance-ai/guidance

Analysis updated 2026-06-21

21,441Jupyter NotebookAudience · developerComplexity · 3/5Setup · moderate

TLDR

Python library that lets you constrain exactly what a language model outputs, forcing it to produce valid JSON, pick from a list of choices, or match a pattern, so you get reliable structured results instead of free-form text.

Mindmap

mindmap
  root((guidance))
    What it does
      Constrained generation
      Structured LLM output
      Reliable parsing
    Constraint types
      Regex patterns
      Select from list
      Context-free grammar
    Backends
      OpenAI API
      Transformers
      llama.cpp
    Audience
      LLM app builders
      Researchers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Force an LLM to output valid JSON by constraining generation with a schema or regular expression, guaranteed every time.

USE CASE 2

Build a multiple-choice classifier where the model can only return one of a predefined list of category names.

USE CASE 3

Extract structured data fields from unstructured text by writing a grammar that describes the exact output shape you need.

What is it built with?

PythonJupyter NotebookTransformersllama.cppOpenAI API

How does it compare?

guidance-ai/guidancezergtant/pytorch-handbookkarpathy/nn-zero-to-hero
Stars21,44121,62821,730
LanguageJupyter NotebookJupyter NotebookJupyter Notebook
Setup difficultymoderatemoderateeasy
Complexity3/52/52/5
Audiencedeveloperresearcherdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires an LLM backend, OpenAI API key, a local llama.cpp model, or a Hugging Face Transformers model, before you can run examples.

License not specified in the explanation.

In plain English

Guidance is a Python library for controlling what a large language model produces. With a normal model, you send a prompt and hope the model returns something in the shape you wanted, Guidance lets you describe that shape directly in code, so the output is guaranteed to fit. The README pitches this as a way to get higher-quality, structured output while reducing latency and cost compared with conventional prompting or fine-tuning. You write a program in regular Python that builds up a conversation with the model using context managers for system, user, and assistant turns, and the library streams generation back into the program where you can capture it by name. The key part is the constraint system. A generation call can be limited by a regular expression, so for instance you can force the model's reply to be only digits when you want a number. There is a select function that forces the answer to be one of a list of choices you supply in advance, useful for multiple-choice questions or any time the valid answers are known. More generally, the constraints can describe any context-free grammar, so you can compose small generation functions into a larger grammar. A Mock model lets you validate a grammar locally without hitting any real model API. The library is installed from PyPI and supports several backends, including Transformers, llama.cpp, and OpenAI. You would reach for Guidance when you are building something on top of a language model and need its output to be reliably parseable or to follow a strict format, for example structured data extraction, picking from a fixed set of options, or workflows that interleave control flow with generation.

Copy-paste prompts

Prompt 1
Using the guidance library with an OpenAI backend, write a program that forces the model to answer a yes/no question with only the word 'yes' or 'no', no other output allowed.
Prompt 2
Show me how to use guidance's select() function to make an LLM classify a support ticket into one of three categories: billing, technical, or general.
Prompt 3
Using guidance with a local llama.cpp model, extract structured fields, name, date, amount, from an invoice description as guaranteed valid JSON.
Prompt 4
How do I use a regular expression constraint in guidance to force an LLM to output a valid US phone number in the format (XXX) XXX-XXXX?
Prompt 5
Show me how to use guidance's Mock model to test and validate a grammar locally without making any API calls.

Frequently asked questions

What is guidance?

Python library that lets you constrain exactly what a language model outputs, forcing it to produce valid JSON, pick from a list of choices, or match a pattern, so you get reliable structured results instead of free-form text.

What language is guidance written in?

Mainly Jupyter Notebook. The stack also includes Python, Jupyter Notebook, Transformers.

What license does guidance use?

License not specified in the explanation.

How hard is guidance to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is guidance for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.