Repository navigation
fix(gemma4 tool calls): a quote inside a string value no longer ends the value (#900) - #905
Merged
Merged
Conversation
…value (#900) Gemma4 writes string arguments as raw text between <|"|> markers. The reader also accepted a plain " or ` as a closer, and took it as one whenever a comma or a closer followed. Code such as np.genfromtxt("a.csv", delimiter=",") or f("q","r") has that shape, so the value was cut short and the rest became a second, malformed call. A plain quote now closes a string only if what follows is the next member (,key: or ,<|"|>), a closer, or the end, and the markers after it pair up (an odd one is the string's own closer). The real <|"|> keeps its rule. Applies to every Gemma4-format model: gemma4e, gemma4-12b, gemma4e-flash, Nemotron-3.5-Bolt. Adds src/test/chat_gemma4_args (no NPU): the #900 shapes, the plain-quote closers that still work, streaming prefixes, and a seeded random sweep. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #900.
Problem
Gemma4 writes string arguments as raw text between
<|"|>markers. The reader also accepts a plain"or`as a closer (the model sometimes writes one instead of<|"|>), and took it as one whenever a,or a closer followed. Code likenp.genfromtxt("train.csv", delimiter=",")orf("q","r")has that shape, so the value was cut short and the rest became a second, malformed call.Fix
scan_gemma4_string(src/common/chat/chat_args.cpp): a plain quote now closes a string only if what follows is the next member (,key:or,<|"|>), a closer, or the end, and the real<|"|>markers after it pair up (an odd one is the string's own closer). The real<|"|>keeps its old rule. One parser path serves every Gemma4-format model: gemma4e, gemma4-12b, gemma4e-flash, Nemotron-3.5-Bolt (same tool-call template as Google's).Only the parser changes; no other component is touched.
Tests
New
src/test/chat_gemma4_args(no NPU, runs on Linux CI): the Gemma4 tool-call parsing splits a call when a string argument contains a double quote (v1.0.11) #900 shapes, plain-quote closers that must keep working, streaming prefixes, a seeded random sweep. Fails 10 checks on the old code, passes now.chat_continuestill passes.Stress (local harness): random Gemma4-style calls with quote/comma/brace-heavy values. Old parser: 1353/2000 wrong. This PR: 0/200,000 (40 seeds), every streaming prefix and truncation checked; ASan/UBSan clean.
Differential on benign calls incl. plain-quote closers and a missing opener: completed parses identical to the old code.
Real models on the NPU (old portable build vs this PR, same 20 code-with-quotes prompts, temperature 0; a prompt passes if it gives exactly one well-formed
file_writecall):* flash never calls a tool under
tool_choice: auto(it answers in markdown), so these usetool_choice: required.Streamed results equal non-streamed on 10/10 (Bolt only).
Perf: 560 KB worst case 61 ms (old 18 ms).
Trade-offs
🤖 Generated with Claude Code