From 49b4d8e58a85e518018b17ef21e51962fe10ccd8 Mon Sep 17 00:00:00 2001 From: Prathamesh Jadhav <55660103+lollinng@users.noreply.github.com> Date: Sat, 6 Jun 2026 02:46:49 +0530 Subject: [PATCH 1/2] Emit {0,n} for at_most so the regex compiles on outlines-core QuantifyMaximum (Term.at_most / at_most) compiled to (...){,n}. Python's re accepts the lower-bound-omitted form, but the default outlines-core backend (Rust regex-automata) does not, so any structured generation using at_most raised 'Failed to build DFA' when the Index was built. Emit the equivalent (...){0,n}. Updates the test that asserted the old output. Co-authored-by: Claude Opus 4.8 (1M context) --- outlines/types/dsl.py | 2 +- tests/types/test_dsl.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/outlines/types/dsl.py b/outlines/types/dsl.py index 255b8bd11..cfd9af88c 100644 --- a/outlines/types/dsl.py +++ b/outlines/types/dsl.py @@ -955,7 +955,7 @@ def to_regex(term: Term) -> str: elif isinstance(term, QuantifyMinimum): return f"({to_regex(term.term)}){{{term.min_count},}}" elif isinstance(term, QuantifyMaximum): - return f"({to_regex(term.term)}){{,{term.max_count}}}" + return f"({to_regex(term.term)}){{0,{term.max_count}}}" elif isinstance(term, QuantifyBetween): return f"({to_regex(term.term)}){{{term.min_count},{term.max_count}}}" else: diff --git a/tests/types/test_dsl.py b/tests/types/test_dsl.py index 6361b534e..3ca3d2e30 100644 --- a/tests/types/test_dsl.py +++ b/tests/types/test_dsl.py @@ -1118,7 +1118,7 @@ def test_to_regex(): assert to_regex(min_term) == r"(a){2,}" max_term = QuantifyMaximum(String("a"), 5) - assert to_regex(max_term) == r"(a){,5}" + assert to_regex(max_term) == r"(a){0,5}" between_term = QuantifyBetween(String("a"), 1, 3) assert to_regex(between_term) == r"(a){1,3}" From 686b4a913181220daf267be6a461f552e9292bd4 Mon Sep 17 00:00:00 2001 From: Prathamesh Jadhav Date: Fri, 19 Jun 2026 17:33:02 +0530 Subject: [PATCH 2/2] Update test_to_regex_simple for {0,n} at_most output The QuantifyMaximum assertion in test_to_regex.py still expected the old (a){,2} form; align it with the (a){0,2} output. --- tests/types/test_to_regex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/types/test_to_regex.py b/tests/types/test_to_regex.py index 6f33fb6e3..8955d6a27 100644 --- a/tests/types/test_to_regex.py +++ b/tests/types/test_to_regex.py @@ -73,7 +73,7 @@ def test_to_regex_simple(): assert a.matches("aaa") is True a = QuantifyMaximum(String("a"), 2) - assert to_regex(a) == "(a){,2}" + assert to_regex(a) == "(a){0,2}" assert a.matches("aa") is True assert a.matches("aaa") is False