HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
guidance-ai
guidance
Jupyter Notebook2023–2026
guidance-ai / guidance

guidance

A guidance language for controlling large language models.

64Distinct people
72Mentions
0Explicit recommenders
21.8KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

A guidance language for controlling large language models.

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 5:04:57 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year72 dated mentions

Observed mentions: 2023-05-09 19:03:22 UTC to 2026-09-15 20:56:14 UTC.

02040602023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 52 mentions; 8 submissions, 44 comments20232024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 12 mentions; 0 submissions, 12 comments20242025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 4 mentions; 0 submissions, 4 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 4 mentions; 1 submissions, 3 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC52844
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC12012
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC404
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC413

From the project README

An excerpt from the repository, fetched Nov 12, 2026.

Read the project’s introduction
Guidance is an efficient programming paradigm for steering language models. With Guidance, you can control how output is structured and get high-quality output for your use case—while reducing latency and cost vs. conventional prompting or fine-tuning. It allows users to constrain generation (e.g. with regex and CFGs) as well as to interleave control (conditionals, loops, tool use) and generation seamlessly. Install Features Install Guidance is available through PyPI and supports a variety of backends (Transformers, llama.cpp, OpenAI, etc.). If you already have the backend required for your model, you can simply run pip install guidance Features A Pythonic interface for language models When using Guidance, you can work with large language models using common Python idioms: from guidance import system, user, assistant, gen from guidance.models import Transformers # Could also do LlamaCpp or many other models phi_lm = Transformers("microsoft/Phi-4-mini-instruct") # Model objects are immutable, so this is a copy lm = phi_lm with system(): lm += "You are a helpful assistant" with user(): lm += "Hello. What is your name?" with assistant(): lm += gen(max_tokens=20) print(lm) If run at the command line, this will produce output like: <|system|>You are a helpful assistant<|end|><|user|>Hello. What is your name?<|end|><|assistant|>I am Phi, an AI developed by Microsoft. How can I help you today? However, if running in a Jupyter notebook, then Guidance provides a widget for a richer user experience: With Guidance, it's really easy to capture generated text: # Get a new copy of the Model lm = phi_lm with system(): lm += "You are a helpful assistant" with user(): lm += "Hello. What is your name?" with assistant(): lm += gen(name="lm_response", max_tokens=20) print(f"{lm['lm_response']=}") lm['lm_response']='I am Phi, an AI developed by Microsoft. How can I help you today?' Guarantee output syntax with constrained generation Guidance provides an easy to use, yet immensely powerful syntax for constraining the output of a language model. For example, a gen() call can be constrained to match a regular expression: lm = phi_lm with system(): lm += "You are a teenager" with user(): lm += "How old are you?" with assistant(): lm += gen("lm_age", regex=r"\d+", temperature=0.8) print(f"The language model is {lm['lm_age']} years old") The language model is 13 years old Often, we know that the output has to be an item from a list we know in advance. Guidance provides a select() function for this scenario: from guidance import select lm = phi_lm with system(): lm += "You are a geography expert" with user(): lm += """What is the capital of Sweden? Answer with the correct letter. A) Helsinki B) Reykjavík C) Stockholm D) Oslo """ with assistant(): lm += select(["A", "B", "C", "D"], name="model_selection") print(f"The model selected {lm['model_selection']}") The model selected C The constraint system offered by Guidance is extremely powerful. It can ensure that the output conforms to any context free grammar (so long as the backend LLM has full support for Guidance). More on this below. Debug grammars offline (no model API calls) When iterating on constraints, you can validate candidate strings locally and test a full run with the Mock model. from guidance import gen from guidance.models import Mock grammar = "expr=" + gen(regex=r"\d+([+*]\d+)*", name="expr") # 1) Validate strings directly against the grammar assert grammar.match("expr=12+7*3") is not None assert grammar.match("expr=12+*3") is None # 2) Run the same grammar with a local mock model lm = Mock(b"<s>expr=12+7*3") lm += grammar print(lm["expr"]) # 12+7*3 Create your own Guidance functions With Guidance, you can create your own Guidance functions which can interact with language models. These are marked using the @guidance decorator. Suppose we wanted to answer lots of multiple choice questions. We could do something like the following: import guidance from guidance.models import Model ASCII_OFFSET = ord("a") @guidance def zero_shot_multiple_choice( language_model: Model, question: str, choices: list[str], ): with user(): language_model += question + "\n" for i, choice in enumerate(choices): language_model += f"{chr(i+ASCII_OFFSET)} : {choice}\n" with assistant(): language_model += select( [chr(i + ASCII_OFFSET) for i in range(len(choices))], name="string_choice" ) return language_model Now, define some questions: questions = [ { "question" : "Which state has the northernmost capital?", "choices" : [ "New South Wales", "Northern Territory", "Queensland", "South Australia", "Tasmania", "Victoria", "Western Australia", ], "answer" : 1, }, { "question" : "Which of the following is venomous?", "choices" : [ "Kangaroo", "Koala Bear", "Platypus", ], "answer" : 2, } ] We can use our decorated function like gen() or select(). The language_model argument will be filled in for us automatically: lm = phi_lm with system(): lm += "You are a student taking a multiple choice test." for mcq in questions: lm_temp = lm + zero_shot_multiple_choice(question=mcq["question"], choices=mcq["choices"]) converted_answer = ord(lm_temp["string_choice"]) - ASCII_OFFSET print(lm_temp) print(f"LM Answer: {converted_answer}, Correct Answer: {mcq['answer']}") <|system|>You are a student taking a multiple choice test.<|end|><|user|>Which state has the northernmost capital? a : New South Wales b : Northern Territory c : Queensland d : South Australia e : Tasmania f : Victoria g : Western Australia <|end|><|assistant|>b LM Answer: 1, Correct Answer: 1 <|system|>You are a student taking a mu
Read the full README on GitHub

What Hacker News says

72 sources
This is a fantastic guide! I did a lot of work on structured generation for my PhD. Here are a few other pointers for people who might be interested: Some libraries: - Outlines, a nice library for structured generation - https://github.com/dottxt-ai/outlines - Guidance (already covered by FlyingLawnmower in this thread), another nice library - https://github.com/guidance-ai/guidance - XGrammar, a less-featureful but really well optimized constrained generation library - https://github.com/mlc-ai/xgrammar - This one has a lot of cool technical aspects that make it an interesting project Some papers: - Efficient Guided Generation for Large Language Models - By the outlines authors, probably the first real LLM constrained generation paper - https://arxiv.org/abs/2307.09702 - Automata-based constraints for language model dec
Read the rest
oding - A much more technical paper about constrained generation and implementation - https://arxiv.org/abs/2407.08103 - Pitfalls, Subtleties, and Techniques in Automata-Based Subword-Level Constrained Generation - A bit of self-promotion. We show where constrained generation can go wrong and discuss some techniques for the practitioner - https://openreview.net/pdf?id=DFybOGeGDS Some blog posts: - Fast, High-Fidelity LLM Decoding with Regex Constraints - Discusses adhering to the canonical tokenization (i.e., not just the constraint, but also what would be produced by the tokenizer) - https://vivien000.github.io/blog/journal/llm-decoding-with-regex-constraints.html - Coalescence: making LLM inference 5x faster - Also from the outlines team - This is about skipping inference during constrained generation if you know there is only one valid token (common in the canonical tokenization setting) - https://blog.dottxt.ai/coalescence.html
In LLM Structured Outputs Handbook
I spent a couple years building a high performance, expressive library for structured outputs in LLMs. Our library is used by OpenAI for structured outputs on the hosted API. Happy to answer questions on how this works: User friendly library that connects to lots of OSS model serving backends: https://github.com/guidance-ai/guidance/ Core Rust library written for high performance mask computation (written mostly by my collaborator @mmoskal): http://github.com/guidance-ai/llguidance
In Sampling and structured outputs in LLMs
I assume they're doing "Structured Generation" or "Guided generation", which has been possible for a while if you control the LLM itself e.g. running an OSS model, e.g. [0][1]. It's cool to see a major API provider offer it, though. The basic idea is: at each auto-regressive step (each token generation), instead of letting the model generate a probability distribution over "all tokens in the entire vocab it's ever seen" (the default), only allow the model to generate a probability distribution over "this specific set of tokens I provide". And that set can change from one sampling set to the next, according to a given grammar. E.g. if you're using a JSON grammar, and you've just generated a `{`, you can provide the model a choice of only which tokens are valid JSON immediately after a `{`, etc. [0] https://github.com/dottxt-ai/outlines [1]
Read the rest
In GPT-5 for Developers
I use something similar to this decorator (more or less a thin wrapper around instructor) and have looked a little bit at the codegen + cache route. It gets more interesting with the addition of tool calls, but I've found JSON outputs create quality degradation and reliability issues. My next experiment on that thread is to either use guidance (https://github.com/guidance-ai/guidance) or reimplement some of their heuristics to try to get tool calling without 100% reliance on JSON.
In smartfunc: Turn Docstrings into LLM-Functions
Interesting paper, but their reason for dismissing constrained decoding methods seems to be that they want to academically study the in-context setting. For practitioners, using a framework like Guidance which forces the models to write valid JSON as they generate text solves this trivially (https://github.com/guidance-ai/guidance) For json in particular these frameworks have functions that take in json schemas or pydantic schemas https://guidance.readthedocs.io/en/latest/generated/guidance...
In StructuredRAG: JSON Response Formatting with Large Language Models

Showing the 15 most recent of 72 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.