Skip to content

[Bugfix] Fix Gemma 4 tool call regex failing on unbalanced braces in string arguments#1127

Closed
Rih0z wants to merge 1 commit intoml-explore:mainfrom
Rih0z:fix/gemma4-regex-unbalanced-braces
Closed

[Bugfix] Fix Gemma 4 tool call regex failing on unbalanced braces in string arguments#1127
Rih0z wants to merge 1 commit intoml-explore:mainfrom
Rih0z:fix/gemma4-regex-unbalanced-braces

Conversation

@Rih0z
Copy link
Copy Markdown

@Rih0z Rih0z commented Apr 8, 2026

Fix _tool_call_regex failing to match when <|"|>-delimited strings contain unbalanced { or }.

Root cause: [^{}] in the regex treats braces inside <|"|>...<|"|> as structural. _gemma4_args_to_json() handles strings correctly but runs after the regex — when the regex fails, it never gets called.

Fix: Shield braces inside <|"|> spans with placeholder characters before regex matching, restore after.

Fixes #1126

Test commands run and results

python -c "..." # Direct function verification (7 tests)
# Existing: nested object, mixed types, array, multiple calls — all PASS
# New: unbalanced open brace, unbalanced close brace, CSS balanced — all PASS

AI Assistance Disclosure

AI assistance (Claude) was used for code analysis, identifying the root cause, and drafting this PR. All changes were reviewed and verified by a human.

🤖 Generated with Claude Code

Co-authored-by: Claude Opus 4.6 (1M context) noreply@anthropic.com

…string arguments

Shield braces inside <|"|>…<|"|> spans before the balanced-brace regex
so that string content like code snippets or partial HTML does not break
the recursive match.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Riho <koki.riho@necam.com>
@angeloskath
Copy link
Copy Markdown
Member

Fixed in #1150 .

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.

[Bug]: Gemma 4 tool call regex fails when string arguments contain unbalanced braces

2 participants