Skip to content

chat : fix gemma4 required tool grammar - #29115

Merged
aldehir merged 1 commit into
ggml-org:masterfrom
aldehir:fix-gemma4-required-grammar
Sep 19, 2026
Merged

aldehir merged 1 commit into
ggml-org:masterfrom
aldehir:fix-gemma4-required-grammar

Conversation

@aldehir

@aldehir aldehir commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Fixes #29089. The parsing for awkward edge cases negatively impacts the grammar when tool_choice = required.

Requirements

@pwilkin

pwilkin commented Sep 19, 2026

Copy link
Copy Markdown
Member

He's right, though. An interaction of two untils is incorrect. His analysis basically shows that if you have two untils, you can have an incorrect parse where the second untils partial parse completes the string that's the delimiter for the first until, i.e.

(<|tool_call)(>something)

@pwilkin pwilkin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For required tool calls this is the right workaround, but we should think about a way to fix the "double until" behavior.

@aldehir

aldehir commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Well, that's why we remove them! It's only a problem in a CFG grammar. The PEG parser, being greedy, doesn't have the same issue. For grammars, ac() gives better guarantees at the cost of ergonomics since the rule consumes the delimiter.

@aldehir

aldehir commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

but we should think about a way to fix the "double until" behavior.

This problem will mostly go away once we add token-aware parsing and we can construct grammars that operate on tokens.

@aldehir aldehir added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Sep 19, 2026
@aldehir
aldehir merged commit f072b10 into ggml-org:master Sep 19, 2026
23 of 27 checks passed
LadislavSopko pushed a commit to 0ics-srls/llama.cpp that referenced this pull request Oct 5, 2026
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PEG→GBNF: until() can stop mid-delimiter, leaving Gemma 4 tool calls unconstrained under tool_choice: required

3 participants