ScriptsMay 11, 2026·2 min read

Guidance — Constrained Generation in Python

Guidance gives you constrained generation (regex, select lists, grammars) in Python. `pip install guidance`, then run with Transformers or other backends.

Agent ready

This asset can be read and installed directly by agents

TokRepo exposes a universal CLI command, install contract, metadata JSON, adapter-aware plan, and raw content links so agents can judge fit, risk, and next actions.

Stage only · 29/100Stage only
Agent surface
Any MCP/CLI agent
Kind
Script
Install
Single
Trust
Trust: Established
Entrypoint
README.md
Universal CLI install command
npx tokrepo install dc8ec1af-aae5-4af4-b355-dffcad6efaf7
Intro

Guidance gives you constrained generation (regex, select lists, grammars) in Python. pip install guidance, then run with Transformers or other backends.

  • Best for: teams who need controllable formats (IDs, enums, templates) and want stronger guarantees than best-effort prompting
  • Works with: Python, Guidance primitives (gen, select), model backends like Transformers/LlamaCpp/OpenAI (per repo)
  • Setup time: 10 minutes

Quantitative Notes

  • Install command: pip install guidance (repo)
  • Setup time ~10 minutes
  • GitHub stars (verified): see Source & Thanks

Practical Notes

Use Guidance as a safety layer when you can't afford invalid formats. Start with simple constraints (regex for numbers/IDs, select() for enums), then graduate to richer grammars. In agent pipelines, put constraints right before boundaries: DB writes, API calls, tool arguments, and routing decisions.

Safety note: Constraints can increase compute; budget latency by keeping grammars small and prompts focused.

FAQ

Q: What is constrained generation? A: You restrict the model to outputs that match a pattern (regex), belong to a list, or follow a grammar—reducing invalid responses.

Q: Do I need a specific model? A: No. The repo mentions multiple backends; you pick one that fits your environment (local Transformers, llama.cpp, hosted APIs).

Q: Where does it help most? A: Any step that must be parseable: routing labels, IDs, enums, JSON-like fields, or template-bound strings.


🙏

Source & Thanks

GitHub: https://github.com/guidance-ai/guidance Owner avatar: https://avatars.githubusercontent.com/u/142035062?v=4 License (SPDX): MIT GitHub stars (verified via api.github.com/repos/guidance-ai/guidance): 21,453

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets