| First name | Last name | |
|---|---|---|
| John | Smith | sales@example.com |
| Jane | Doe | support@example.com |
Unstructured data:
âMy name is John Smith and you can contact me at sales@example.com and she is Jane Doe and can be contacted at support@example.comâ
â Structured data:
| First name | Last name | |
|---|---|---|
| John | Smith | sales@example.com |
| Jane | Doe | support@example.com |
Unstructured data â Structured data
| Department | |
|---|---|
| I would like to have more information related to the new product. | Sales |
| Are there any openings at your company? | HR |
| I cannot exit Vim in my computer. Could you help me with that? | IT |
Unstructured data:
âAlice loves Bob but she hates Charlesâ
â Structured data:
Unstructured data:
âWhatâs the temperature in San Francisco now? How about tomorrow?â
â Structured data:
| Tool | Tool arguments |
|---|---|
| get_current_temperature | {'location': 'San Francisco'} |
| get_temperature_by_date | {'location': 'San Francisco', 'date': '2025-12-03'} |
Unstructured data:
âMake a program in Python that prints âHello Worldââ
â Structured data:
The three approachesâmodifying weights, improving prompts, and constraining generationâare complementary and should NOT be viewed as mutually exclusive.
GPT-4o fails to follow this instruction 1

While a 0.5B model can do it 1
How is this possible?
This needs some explanation:
The LLM outputs for the next token the whole probability distribution over all the tokens
The LLM samples the next token from this probability distribution
However, some of these rules can be bent. Others can be broken.
https://alonsosilva-nexttokenprediction.hf.space
Nobody has problems similar to as not using a letter.
Really?
One might think that both problems are unrelated.
My goal is to show that they are very similar.
A small (related) detour
A deterministic finite automaton \(\mathcal{A}\) is a tuple \((Q, \Sigma, q_0, F, \delta)\) where:
A nondeterministic finite automaton \(\mathcal{A}\) is a tuple \((Q, \Sigma, q_0, F, \delta)\) where:
Every nondeterministic finite automaton (NFA) has an equivalent deterministic finite automaton (DFA).
Let \(A\) and \(B\) be languages. We define the regular operations union, concatenation, and star as follows:
We say that \(R\) is a regular expression if \(R\) is
Any regular expression can be converted into a deterministic finite automaton that recognizes the language it describes, and vice versa.

Fast, High-Fidelity LLM Decoding with Regex Constraints by Vivien Tran-Thien

Fast, High-Fidelity LLM Decoding with Regex Constraints by Vivien Tran-Thien

Fast, High-Fidelity LLM Decoding with Regex Constraints by Vivien Tran-Thien
For example, for sentiment analysis:
Deterministic finite transducer
If \(A\) is a regular language, then there is a number \(p\) (the pumping length) where if \(s\) is any string in \(A\) of length at least \(p\), then \(s\) may be divided into three pieces, \(s=xyz\), satisfying the following conditions:
Let \(B\) be the language \(\{0^n1^n: n\ge0\}\).
\(B\) is not regular.
Consider the following source code:
module(
expression_statement(
call(
identifier: 'print'
argument_list(
(: '('
string(
string_start: '"'
string_content: 'Hello'
string_end: '"'
)
,: ','
string(
string_start: '"'
string_content: 'World'
string_end: '"'
)
): ')'
)
)
)
)
'print(\n "Hello", "World"\n)\n'
The parser attemps to:
Let \(B\) be the language \(\{0^n1^n: n\ge0\}\).
\(B\) is not regular.
The following is an example of a context-free grammar \(G\)
\(A\to 0A1\)
\(A\to B\)
\(B\to \#\)
The grammar \(G\) can generate the string \(000\#111\).
\(A\) \(\implies\) \(0A1\) \(\implies\) \(00A11\) \(\implies\) \(000A111\) \(\implies\) \(000B111\) \(\implies\) \(000\#111\)
A context-free grammar is a \(4\)-tuple \((V,\Sigma,R,S)\) where
A pushdown automaton is a \(6\)-tuple \((Q,\Sigma,\Gamma,\delta,q_0,F)\) where \(Q\), \(\Sigma\), \(\Gamma\) and \(F\) are finite sets, and
We can also use a state diagram to describe a PDA. The following is a state diagram for the PDA that recognizes \(\{0^n1^n: n\ge0\}\).
A language is context free if and only if some pushdown automaton recognizes it.