Regular expression constraints

While you can specify any constraint you want with raw guidance functions/grammars, it is often useful to enforce very simple patterns on our gen() calls. To do this you can specify regular expression formats to which generated text must adhere. Internally these expressions are converted to native guidance grammars (set of guidance functions).

Example

In the following example we know that we want to get number for the generated chapter variable, but GPT2 does not know that, and instead makes up something else.

Invalid output without a regex guide

[1]:
from guidance import models, gen

gpt2 = models.Transformers("gpt2")

gpt2 + f"""\
Rewrite this proverb to apply to model instructions instead.

Where there is no guidance, a people falls,
but in an abundance of counselors there is safety.
== Proverbs 11:14

UPDATED
Where there is no guidance{gen('rewrite', stop="==")}
== GPT {gen('chapter', max_tokens=10)}:{gen('verse', max_tokens=10)}"""
gpustat is not installed, run `pip install gpustat` to collect GPU stats.
[1]:
<guidance.models._transformers.Transformers at 0x108f401f320>

Valid output with a regex guide

[2]:
gpt2 + f"""\
Tweak this proverb to apply to model instructions instead.

Where there is no guidance, a people falls,
but in an abundance of counselors there is safety.
== Proverbs 11:14

UPDATED
Where there is no guidance{gen('rewrite', stop="==")}
== GPT {gen('chapter', regex="[0-9]+")}:{gen('verse', regex="[0-9]+")}"""
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 1
----> 1 gpt2 + f"""\
      2 Tweak this proverb to apply to model instructions instead.
      3
      4 Where there is no guidance, a people falls,
      5 but in an abundance of counselors there is safety.
      6 == Proverbs 11:14
      7
      8 UPDATED
      9 Where there is no guidance{gen('rewrite', stop="==")}
     10 == GPT {gen('chapter', regex="[0-9]+")}:{gen('verse', regex="[0-9]+")}"""

File ~\source\repos\guidance\guidance\models\_base\_model.py:104, in Model.__add__(self, other)
    102     return other(self)
    103 if isinstance(other, ASTNode):
--> 104     self = self._apply_node(other)
    105     self = self._update_open_block_captures()
    106     return self

File ~\source\repos\guidance\guidance\models\_base\_model.py:132, in Model._apply_node(self, node)
    129 else:
    130     self._update_trace_node(self._id, self._parent_id, StatelessGuidanceInput(value=node))
--> 132 for i, output_attr in enumerate(self._interpreter.run(node)):
    133     if isinstance(output_attr, TextOutput):
    134         # TODO: put this elsewhere (inside state?)
    135         self.token_count += output_attr.token_count

File ~\source\repos\guidance\guidance\models\_base\_interpreter.py:36, in Interpreter.run(self, node, **kwargs)
     35 def run(self, node: ASTNode, **kwargs) -> Iterator[OutputAttr]:
---> 36     yield from node.simplify()._run(self, **kwargs)

File ~\source\repos\guidance\guidance\models\_engine\_interpreter.py:65, in EngineInterpreter.grammar(self, node, **kwargs)
     57 engine_gen = self.engine(
     58     state=self.state,
     59     grammar=node.ll_grammar(),
     60     ensure_bos_token=True,
     61     echo=False,
     62 )
     64 delayed_bytes = b""
---> 65 for chunk in engine_gen:
     66     new_bytes = chunk.new_bytes
     67     new_text, delayed_bytes = partial_decode(new_bytes)

File ~\source\repos\guidance\guidance\models\_engine\_engine.py:175, in Engine.__call__(self, state, grammar, ensure_bos_token, echo)
    172 while not parser.done():
    173     t0 = time.time()
--> 175     tokens, mask_fut, backtrack = parser.advance(engine_output)
    177     # Note that has_pending_stop implies that the response is a stop response,
    178     # but the converse is not true. We can therefore avoid some (but not all)
    179     # unnecessary calls to get_logits on the final iteration.
    180     has_pending_stop = parser.has_pending_stop()

File ~\source\repos\guidance\guidance\_parser.py:70, in TokenParser.advance(self, engine_output)
     67 if self.done():
     68     raise TokenParserException("Cannot advance on a done parser")
---> 70 return self._generator.send(engine_output)

File ~\source\repos\guidance\guidance\_parser.py:145, in TokenParser._parse(self, prompt, ensure_bos_token)
    136 if not mask[engine_output.issued_token.token_id]:
    137     # Note: we could punt this probem to ll_interpreter.post_process,
    138     # but it's a bit clearer to handle it here
    139     raise InvalidTokenException(
    140         token=engine_output.issued_token.token_id,
    141         valid_tokens=[i for i in range(len(mask)) if mask[i]],
    142         prompt_tokens=tokens
    143     )
--> 145 backtrack, ff_tokens = self.ll_interpreter.commit_token(
    146     engine_output.issued_token.token_id
    147 )
    148 if backtrack:
    149     tokens = tokens[:-backtrack]

ValueError: panic: lexer_stack=[LexerState { row_idx: 0, lexer_state: StateID(19,0), byte: None }, LexerState { row_idx: 0, lexer_state: StateID(20,0), byte: Some(84) }, LexerState { row_idx: 0, lexer_state: StateID(21,0), byte: Some(119) }, LexerState { row_idx: 0, lexer_state: StateID(22,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(23,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(24,0), byte: Some(107) }, LexerState { row_idx: 0, lexer_state: StateID(25,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(26,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(27,0), byte: Some(104) }, LexerState { row_idx: 0, lexer_state: StateID(28,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(29,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(30,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(31,0), byte: Some(112) }, LexerState { row_idx: 0, lexer_state: StateID(32,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(33,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(34,0), byte: Some(118) }, LexerState { row_idx: 0, lexer_state: StateID(35,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(36,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(37,0), byte: Some(98) }, LexerState { row_idx: 0, lexer_state: StateID(38,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(39,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(40,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(41,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(42,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(43,0), byte: Some(112) }, LexerState { row_idx: 0, lexer_state: StateID(44,0), byte: Some(112) }, LexerState { row_idx: 0, lexer_state: StateID(45,0), byte: Some(108) }, LexerState { row_idx: 0, lexer_state: StateID(46,0), byte: Some(121) }, LexerState { row_idx: 0, lexer_state: StateID(47,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(48,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(49,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(50,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(51,0), byte: Some(109) }, LexerState { row_idx: 0, lexer_state: StateID(52,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(53,0), byte: Some(100) }, LexerState { row_idx: 0, lexer_state: StateID(54,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(55,0), byte: Some(108) }, LexerState { row_idx: 0, lexer_state: StateID(56,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(57,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(58,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(59,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(60,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(61,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(62,0), byte: Some(117) }, LexerState { row_idx: 0, lexer_state: StateID(63,0), byte: Some(99) }, LexerState { row_idx: 0, lexer_state: StateID(64,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(65,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(66,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(67,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(68,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(69,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(70,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(71,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(72,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(73,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(74,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(75,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(76,0), byte: Some(100) }, LexerState { row_idx: 0, lexer_state: StateID(77,0), byte: Some(46) }, LexerState { row_idx: 0, lexer_state: StateID(78,0), byte: Some(10) }, LexerState { row_idx: 0, lexer_state: StateID(79,0), byte: Some(10) }, LexerState { row_idx: 0, lexer_state: StateID(80,0), byte: Some(87) }, LexerState { row_idx: 0, lexer_state: StateID(81,0), byte: Some(104) }, LexerState { row_idx: 0, lexer_state: StateID(82,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(83,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(84,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(85,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(86,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(87,0), byte: Some(104) }, LexerState { row_idx: 0, lexer_state: StateID(88,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(89,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(90,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(91,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(92,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(93,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(94,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(95,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(96,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(97,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(98,0), byte: Some(103) }, LexerState { row_idx: 0, lexer_state: StateID(99,0), byte: Some(117) }, LexerState { row_idx: 0, lexer_state: StateID(100,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(101,0), byte: Some(100) }, LexerState { row_idx: 0, lexer_state: StateID(102,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(103,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(104,0), byte: Some(99) }, LexerState { row_idx: 0, lexer_state: StateID(105,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(106,0), byte: Some(44) }, LexerState { row_idx: 0, lexer_state: StateID(107,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(108,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(109,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(110,0), byte: Some(112) }, LexerState { row_idx: 0, lexer_state: StateID(111,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(112,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(113,0), byte: Some(112) }, LexerState { row_idx: 0, lexer_state: StateID(114,0), byte: Some(108) }, LexerState { row_idx: 0, lexer_state: StateID(115,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(116,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(117,0), byte: Some(102) }, LexerState { row_idx: 0, lexer_state: StateID(118,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(119,0), byte: Some(108) }, LexerState { row_idx: 0, lexer_state: StateID(120,0), byte: Some(108) }, LexerState { row_idx: 0, lexer_state: StateID(121,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(122,0), byte: Some(44) }, LexerState { row_idx: 0, lexer_state: StateID(123,0), byte: Some(10) }, LexerState { row_idx: 0, lexer_state: StateID(124,0), byte: Some(98) }, LexerState { row_idx: 0, lexer_state: StateID(125,0), byte: Some(117) }, LexerState { row_idx: 0, lexer_state: StateID(126,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(127,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(128,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(129,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(130,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(131,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(132,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(133,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(134,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(135,0), byte: Some(98) }, LexerState { row_idx: 0, lexer_state: StateID(136,0), byte: Some(117) }, LexerState { row_idx: 0, lexer_state: StateID(137,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(138,0), byte: Some(100) }, LexerState { row_idx: 0, lexer_state: StateID(139,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(140,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(141,0), byte: Some(99) }, LexerState { row_idx: 0, lexer_state: StateID(142,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(143,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(144,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(145,0), byte: Some(102) }, LexerState { row_idx: 0, lexer_state: StateID(146,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(147,0), byte: Some(99) }, LexerState { row_idx: 0, lexer_state: StateID(148,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(149,0), byte: Some(117) }, LexerState { row_idx: 0, lexer_state: StateID(150,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(151,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(152,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(153,0), byte: Some(108) }, LexerState { row_idx: 0, lexer_state: StateID(154,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(155,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(156,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(157,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(158,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(159,0), byte: Some(104) }, LexerState { row_idx: 0, lexer_state: StateID(160,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(161,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(162,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(163,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(164,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(165,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(166,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(167,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(168,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(169,0), byte: Some(102) }, LexerState { row_idx: 0, lexer_state: StateID(170,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(171,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(172,0), byte: Some(121) }, LexerState { row_idx: 0, lexer_state: StateID(173,0), byte: Some(46) }, LexerState { row_idx: 0, lexer_state: StateID(174,0), byte: Some(10) }, LexerState { row_idx: 0, lexer_state: StateID(175,0), byte: Some(61) }, LexerState { row_idx: 0, lexer_state: StateID(176,0), byte: Some(61) }, LexerState { row_idx: 0, lexer_state: StateID(177,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(178,0), byte: Some(80) }, LexerState { row_idx: 0, lexer_state: StateID(179,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(180,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(181,0), byte: Some(118) }, LexerState { row_idx: 0, lexer_state: StateID(182,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(183,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(184,0), byte: Some(98) }, LexerState { row_idx: 0, lexer_state: StateID(185,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(186,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(187,0), byte: Some(49) }, LexerState { row_idx: 0, lexer_state: StateID(188,0), byte: Some(49) }, LexerState { row_idx: 0, lexer_state: StateID(189,0), byte: Some(58) }, LexerState { row_idx: 0, lexer_state: StateID(190,0), byte: Some(49) }, LexerState { row_idx: 0, lexer_state: StateID(191,0), byte: Some(52) }, LexerState { row_idx: 0, lexer_state: StateID(192,0), byte: Some(10) }, LexerState { row_idx: 0, lexer_state: StateID(193,0), byte: Some(10) }, LexerState { row_idx: 0, lexer_state: StateID(194,0), byte: Some(85) }, LexerState { row_idx: 0, lexer_state: StateID(195,0), byte: Some(80) }, LexerState { row_idx: 0, lexer_state: StateID(196,0), byte: Some(68) }, LexerState { row_idx: 0, lexer_state: StateID(197,0), byte: Some(65) }, LexerState { row_idx: 0, lexer_state: StateID(198,0), byte: Some(84) }, LexerState { row_idx: 0, lexer_state: StateID(199,0), byte: Some(69) }, LexerState { row_idx: 0, lexer_state: StateID(200,0), byte: Some(68) }, LexerState { row_idx: 0, lexer_state: StateID(201,0), byte: Some(10) }, LexerState { row_idx: 0, lexer_state: StateID(202,0), byte: Some(87) }, LexerState { row_idx: 0, lexer_state: StateID(203,0), byte: Some(104) }, LexerState { row_idx: 0, lexer_state: StateID(204,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(205,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(206,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(207,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(208,0), byte: Some(116) }, LexerState { row_idx: 0, lexer_state: StateID(209,0), byte: Some(104) }, LexerState { row_idx: 0, lexer_state: StateID(210,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(211,0), byte: Some(114) }, LexerState { row_idx: 0, lexer_state: StateID(212,0), byte: Some(101) }, LexerState { row_idx: 0, lexer_state: StateID(213,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(214,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(215,0), byte: Some(115) }, LexerState { row_idx: 0, lexer_state: StateID(216,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(217,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(218,0), byte: Some(111) }, LexerState { row_idx: 0, lexer_state: StateID(219,0), byte: Some(32) }, LexerState { row_idx: 0, lexer_state: StateID(220,0), byte: Some(103) }, LexerState { row_idx: 0, lexer_state: StateID(221,0), byte: Some(117) }, LexerState { row_idx: 0, lexer_state: StateID(222,0), byte: Some(105) }, LexerState { row_idx: 0, lexer_state: StateID(223,0), byte: Some(100) }, LexerState { row_idx: 0, lexer_state: StateID(224,0), byte: Some(97) }, LexerState { row_idx: 0, lexer_state: StateID(225,0), byte: Some(110) }, LexerState { row_idx: 0, lexer_state: StateID(226,0), byte: Some(99) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: None }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(44) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(97) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(112) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(101) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(111) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(112) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(108) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(101) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(102) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(97) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(108) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(108) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(115) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(44) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(98) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(117) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(116) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(105) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(110) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(97) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(110) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(97) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(98) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(117) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(110) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(100) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(97) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(110) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(99) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(101) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(111) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(102) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(99) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(111) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(117) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(110) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(115) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(101) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(108) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(111) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(114) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(115) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(116) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(104) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(101) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(114) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(101) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(105) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(115) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(32) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(115) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(97) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(102) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(101) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(116) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(121) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(46) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(10) }, LexerState { row_idx: 1, lexer_state: StateID(3,0), byte: Some(10) }, LexerState { row_idx: 1, lexer_state: StateID(229,0), byte: Some(61) }, LexerState { row_idx: 2, lexer_state: StateID(232,0), byte: None }, LexerState { row_idx: 2, lexer_state: StateID(238,0), byte: Some(10) }, LexerState { row_idx: 2, lexer_state: StateID(239,0), byte: Some(61) }, LexerState { row_idx: 2, lexer_state: StateID(240,0), byte: Some(61) }, LexerState { row_idx: 2, lexer_state: StateID(241,0), byte: Some(32) }, LexerState { row_idx: 2, lexer_state: StateID(242,0), byte: Some(71) }, LexerState { row_idx: 2, lexer_state: StateID(243,0), byte: Some(80) }, LexerState { row_idx: 2, lexer_state: StateID(244,0), byte: Some(84) }, LexerState { row_idx: 3, lexer_state: StateID(246,0), byte: None }, LexerState { row_idx: 3, lexer_state: StateID(247,0), byte: Some(49) }, LexerState { row_idx: 3, lexer_state: StateID(247,0), byte: Some(48) }, LexerState { row_idx: 3, lexer_state: StateID(247,0), byte: Some(49) }, LexerState { row_idx: 5, lexer_state: StateID(246,0), byte: None }, LexerState { row_idx: 5, lexer_state: StateID(247,0), byte: Some(49) }] bytes="Tweak this proverb to apply to model instructions instead.\n\nWhere there is no guidance, a people falls,\nbut in an abundance of counselors there is safety.\n== Proverbs 11:14\n\nUPDATED\nWhere there is no guidance, a people falls,but in an abundance of counselors there is safety.\n\n\n== GPT 101:1" 293!=290+1
   0: llg_clone_matcher
   1: llg_clone_matcher
   2: llg_clone_matcher
   3: llg_clone_matcher
   4: llg_clone_matcher
   5: llg_clone_matcher
   6: llg_clone_matcher
   7: llg_clone_matcher
   8: llg_clone_matcher
   9: llg_clone_matcher
  10: llg_clone_matcher
  11: llg_clone_matcher
  12: llg_clone_matcher
  13: llg_clone_matcher
  14: llg_clone_matcher
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: method_vectorcall_VARARGS_KEYWORDS
             at \Objects\descrobject.c:365
  19: _PyObject_VectorcallTstate
             at \Include\internal\pycore_call.h:92
  20: PyObject_Vectorcall
             at \Objects\call.c:325
  21: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:2715
  22: _PyEval_EvalFrame
             at \Include\internal\pycore_ceval.h:89
  23: gen_send_ex2
             at \Objects\genobject.c:230
  24: gen_send_ex
             at \Objects\genobject.c:274
  25: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:3094
  26: _PyEval_EvalFrame
             at \Include\internal\pycore_ceval.h:89
  27: gen_send_ex2
             at \Objects\genobject.c:230
  28: gen_iternext
             at \Objects\genobject.c:603
  29: enum_next
             at \Objects\enumobject.c:231
  30: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:2324
  31: _PyFunction_Vectorcall
             at \Objects\call.c:424
  32: _PyObject_VectorcallTstate
             at \Include\internal\pycore_call.h:92
  33: vectorcall_unbound
             at \Objects\typeobject.c:2236
  34: vectorcall_maybe
             at \Objects\typeobject.c:2288
  35: slot_nb_add
             at \Objects\typeobject.c:8588
  36: binary_op1
             at \Objects\abstract.c:882
  37: PyNumber_Add
             at \Objects\abstract.c:1062
  38: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:3391
  39: _PyEval_EvalFrame
             at \Include\internal\pycore_ceval.h:89
  40: _PyEval_Vector
             at \Python\ceval.c:1685
  41: PyEval_EvalCode
             at \Python\ceval.c:580
  42: builtin_exec_impl
             at \Python\bltinmodule.c:1096
  43: builtin_exec
             at \Python\clinic\bltinmodule.c.h:586
  44: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:2975
  45: _PyEval_EvalFrame
             at \Include\internal\pycore_ceval.h:89
  46: gen_send_ex2
             at \Objects\genobject.c:230
  47: gen_send_ex
             at \Objects\genobject.c:274
  48: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:3094
  49: _PyFunction_Vectorcall
             at \Objects\call.c:424
  50: _PyObject_VectorcallTstate
             at \Include\internal\pycore_call.h:92
  51: method_vectorcall
             at \Objects\classobject.c:61
  52: _PyVectorcall_Call
             at \Objects\call.c:283
  53: _PyObject_Call
             at \Objects\call.c:354
  54: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:3263
  55: _PyEval_EvalFrame
             at \Include\internal\pycore_ceval.h:89
  56: gen_send_ex2
             at \Objects\genobject.c:230
  57: PyGen_am_send
             at \Objects\genobject.c:267
  58: <unknown>
  59: <unknown>
  60: cfunction_vectorcall_O
             at \Objects\methodobject.c:509
  61: _PyObject_VectorcallTstate
             at \Include\internal\pycore_call.h:92
  62: context_run
             at \Python\context.c:668
  63: cfunction_vectorcall_FASTCALL_KEYWORDS
             at \Objects\methodobject.c:438
  64: _PyVectorcall_Call
             at \Objects\call.c:271
  65: _PyObject_Call
             at \Objects\call.c:354
  66: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:3263
  67: _PyEval_EvalFrame
             at \Include\internal\pycore_ceval.h:89
  68: _PyEval_Vector
             at \Python\ceval.c:1685
  69: PyEval_EvalCode
             at \Python\ceval.c:580
  70: builtin_exec_impl
             at \Python\bltinmodule.c:1096
  71: builtin_exec
             at \Python\clinic\bltinmodule.c.h:586
  72: cfunction_vectorcall_FASTCALL_KEYWORDS
             at \Objects\methodobject.c:438
  73: _PyObject_VectorcallTstate
             at \Include\internal\pycore_call.h:92
  74: PyObject_Vectorcall
             at \Objects\call.c:325
  75: _PyEval_EvalFrameDefault
             at \PCbuild\Python\bytecodes.c:2715
  76: _PyFunction_Vectorcall
             at \Objects\call.c:424
  77: _PyVectorcall_Call
             at \Objects\call.c:271
  78: _PyObject_Call
             at \Objects\call.c:354
  79: PyObject_Call
             at \Objects\call.c:379
  80: pymain_run_module
             at \Modules\main.c:300
  81: pymain_run_python
             at \Modules\main.c:628
  82: Py_RunMain
             at \Modules\main.c:714
  83: pymain_main
             at \Modules\main.c:744
  84: Py_Main
             at \Modules\main.c:756
  85: invoke_main
             at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:90
  86: __scrt_common_main_seh
             at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  87: BaseThreadInitThunk
  88: RtlUserThreadStart

<state>
Tokens: ⟦Twe‧ak‧ this‧ proverb‧ to‧ apply‧ to‧ model‧ instructions‧ instead‧.‧\n‧\n‧Where‧ there‧ is‧ no‧ guidance‧,‧ a‧ people‧ falls‧,‧\n‧but‧ in‧ an‧ abundance‧ of‧ counselors‧ there‧ is‧ safety‧.‧\n‧==‧ Pro‧verbs‧ 11‧:‧14‧\n‧\n‧U‧PDATED‧\n‧Where‧ there‧ is‧ no‧ guidance‧,‧ a‧ people‧ falls‧,‧but‧ in‧ an‧ abundance‧ of‧ counselors‧ there‧ is‧ safety‧.‧\n‧\n‧\n‧==‧ G‧PT‧ 101‧:‧1⟧
75 tokens, 290 bytes; grm_prefix: ""
Flags: had_backtrack
Parser: {
  "compute_time_us": 23165,
  "rows": 34,
  "cached_rows": 354,
  "all_items": 47,
  "lexer_cost": 6420,
  "slices_applied": 0,
  "trie_nodes_walked": 1766059,
  "definitive_bytes": 292,
  "lexer_ops": 0,
  "num_lex_errors": 0,
  "num_lexemes": 0
}
Stop: NotStopped
Error: None
</state>

Have an idea for more helpful examples? Pull requests that add to this documentation notebook are encouraged!