Constraining an LLM output to match a regular expression

Hi! I’m happy to share a new Community Blog Post introducing two algorithms that guarantee that an LLM output will match an arbitrary regex: https://huggingface.co/blog/vivien/llm-decoding-with-regex-constraints.

It comes with a detailed notebook and a technical appendix with the formal description of the algorithms and their correctness proof.

If you’re looking for a TL;DR, please have a look at this Twitter thread: https://x.com/vivien000000/status/1760933100798767314?s=20

4 Likes