Guidance

Guidance language for controlling LLM generation with constraints, grammars, and JSON schemas.

Open SourceSelf HostedOffline Capable
0.0 (0)

About

Guidance approaches LLM control as a programming problem rather than prompt writing. The Python framework constrains generation with regex patterns, context-free grammars, and JSON schemas, including Pydantic models, and lets developers interleave conditionals, loops, tool calls, and generation inside composable decorated functions. Its gen() and select() primitives capture output into named variables or force a choice among fixed options, so responses always parse. A notable optimization is token fast-forwarding: any tokens the grammar makes inevitable are filled in without model forward passes, cutting latency and GPU cost during structured generation. Backends include Hugging Face Transformers, llama.cpp, and OpenAI-compatible APIs, and a Mock model allows offline grammar debugging. Installable from PyPI and released under the MIT license, Guidance is used by engineers who need guaranteed structured output from both local and hosted models.

Should you use Guidance?

Pick it when

Pick Guidance when you run models locally through Transformers or llama.cpp and need output that always parses, via regex, grammars, or JSON schemas mixed with Python control flow, and want token fast-forwarding to cut latency and GPU cost.

Look elsewhere when

Skip it if you mostly call hosted APIs and just want validated objects, where Instructor is simpler. If you only need valid JSON or regex output, Outlines is the narrower, widely adopted pick, and BAML suits multi-language teams.

Alternatives to Guidance

  • Outlines

    Narrower FSM-based constrained decoding used by vLLM and Hugging Face, simpler when you need valid output without interleaved control flow.

  • Instructor

    Validation and retry over provider SDKs, the easiest path with hosted APIs, but no first-pass guarantee and no token-level control.

  • BAML

    Typed functions with generated clients for several languages and post-hoc schema parsing, better for mixed hosted providers than token-level control.

Reviews (0)

Leave a Review

No reviews yet. Be the first to review!