Skip to content

Add anything and until DSL terms for reasoning models - #1978

Open
rs-03 wants to merge 1 commit into
dottxt-ai:mainfrom
rs-03:add-anything-until-dsl
Open

Add anything and until DSL terms for reasoning models#1978
rs-03 wants to merge 1 commit into
dottxt-ai:mainfrom
rs-03:add-anything-until-dsl

Conversation

@rs-03

@rs-03 rs-03 commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Adds the anything and until DSL constructs requested in #1480, so structured generation can let a model produce free-form text up to a delimiter before switching to a structured schema. This is the common reasoning-model pattern:

from outlines.types import anything, either

outline = "<think>" + anything.until("</think>") + "</think>" + either("yes", "no")

anything corresponds to .*. anything.until(delimiter) matches any text up to, but not including, a literal delimiter. Since outlines-core does not support lookaheads, the negative-lookahead form ((?!</think>).)* is expanded into the equivalent alternation, as suggested in the issue:

([^<]|<[^/]|</[^t]|</t[^h]|</th[^i]|</thi[^n]|</thin[^k]|</think[^>])*

Closes #1480

Design choices worth your input

  • until excludes the delimiter (it stops just before it), matching the expansion above. The issue notes "we could also decide that until keeps the </think> token"; I went with the excluding version, and I am happy to change it if you prefer keeping the token.
  • Only literal string delimiters are supported in this first iteration; until_regex is deferred as suggested in the issue.
  • Delimiter characters are passed through re.escape, so a delimiter containing regex metacharacters is matched literally. As a side effect the generated pattern uses, for example, [^/] where the issue illustration wrote [^\/]; the two are equivalent in Python regex, and using re.escape keeps it robust for arbitrary delimiters.

Changes

  • Anything term (with an until method) and the anything singleton in outlines/types/dsl.py, plus a to_regex branch mapping anything to .*
  • Exported anything from outlines.types
  • Five unit tests in tests/types/test_dsl.py covering the expanded pattern, matching behaviour (including newlines and delimiter rejection), special-character escaping, the empty-delimiter guard, and the end-to-end reasoning outline

Ran locally: pytest tests/types/test_dsl.py -k anything (5 passed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add anything and until method in the DSL for reasoning models

1 participant