Skip to content

common : handle missing gbnf regex anchors with .* fallback - #26915

Closed
RayanVakil wants to merge 1 commit into
ggml-org:masterfrom
RayanVakil:fix-gbnf-regex-anchors
Closed

RayanVakil wants to merge 1 commit into
ggml-org:masterfrom
RayanVakil:fix-gbnf-regex-anchors

Conversation

@RayanVakil

@RayanVakil RayanVakil commented Aug 11, 2026 •

Copy link
Copy Markdown

Overview

This PR addresses a strict validation failure in json-schema-to-grammar.cpp. When a JSON schema pattern lacks ^ or $ anchors, the current regex compiler throws a hard error. This patch surgically modifies _visit_pattern to gracefully fallback by prepending/appending .* to unanchored patterns. This ensures valid GBNF grammar generation without breaking existing anchored schema validations.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - Used an AI assistant strictly to automate the Git CLI branching workflow and format a targeted, surgical regex fallback patch. I manually reviewed the logic, verified the architectural impact, and validated the local compilation prior to submission.

@RayanVakil
RayanVakil requested a review from a team as a code owner August 11, 2026 16:53
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

Hi @RayanVakil, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Aug 11, 2026
@aldehir

aldehir commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

This makes the GBNF grammar accept anything, rendering it useless.

@RayanVakil

Copy link
Copy Markdown
Author

@aldehir Ah yeah, good call. I was mostly just trying to hotfix a regex compiler crash that was bricking my local pipeline, but you're completely right. Injecting .* totally defeats the strict token constraints of GBNF by letting the model hallucinate whatever it wants before or after the schema.

I'll go ahead and close this out. Thanks for the quick review and catching the broader impact!

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

Labels

draft PR will be changed to draft by github-actions bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants