Repository navigation
Tool parsers: return well-formed calls that break only their schema (GLM5, Gemma, MiMo V2; d-inference#2156) - #434
Merged
Conversation
A GLM-5.3-Flash frame that follows the tool-call grammar but omits a required argument, carries an argument the schema does not declare, or gives a parameter no usable type is refused today, so the provider returns its markup as text (d-inference#2156). These tests expect the call the model made; frames that break the grammar still fail closed. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
GLM5ToolCallParser refused a well-formed frame whose call left out a required argument, carried an argument the schema does not declare, or filled a parameter without a usable type, so servers returned the frame as text (d-inference#2156). Its header already said parsing is not schema validation. The parser now checks the grammar and the declared function name only and returns such a call as generated. A value declared only as string stays raw text; a value of another declared type is JSON when it matches that type; any other value is JSON when its raw text parses (for a union with string, only as one of the other types), else that raw text, as vLLM and SGLang read it. Without a type, a value ends at its first </arg_value>. Grammar failures (open or nested frames, misplaced tags, a repeated argument, an undeclared function) still fail and still refuse the whole batch at EOS. Tests that pinned the old refusals now pin the returned values. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
GLM5ToolCallParser.argumentTypes(_:parameters:) returns the JSON types a declaration gives an argument (the exact declared key's schema, else additionalProperties, plus a nullable null). They only choose between a value's raw and JSON readings. d-inference's GLM tool-suffix lexer reads frame boundaries the way this parser does and now takes the same types from here instead of keeping its own copy of the rule. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… (red) One matrix over the served formats (Gemma, Harmony, Qwen 3.5, XML, Nemotron, MiMo V2, GLM5, JSON), whole and streamed, alone and beside valid calls: a call that omits a required argument, adds an undeclared one (additionalProperties absent or false), fills an untyped, a nullable union or a mismatched parameter keeps its format's grammar, so it is returned as generated. Red today for Gemma (an undeclared argument under additionalProperties false) and MiMo V2 (a union or a value of another type); GLM5 passes after the previous commits (red on main). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The matrix test found two more parsers that refuse a well-formed call for its schema: Gemma (an undeclared argument under additionalProperties: false; the provider then shows the frame as text) and MiMo V2 (a union or a value of another type; the provider then fails the response with a 500). - GemmaFunctionParser no longer refuses undeclared arguments. - MiMoV2ToolCallParser reads a value of a declared type other than string as JSON when it parses as one (for a union with string, only as one of the other types), else as its raw text; an untyped value stays raw text, as before. - GrammarOnlyToolParsing (DARKBLOOM_GRAMMAR_ONLY_TOOL_PARSING; unset or any other value on, 0/off/false/no off) switches the three parsers back to their schema refusals. GLM5ToolCallParser, GemmaFunctionParser and MiMoV2ToolCallParser take grammarOnly in init, defaulting to it; GLM5's refusals are re-checked after a parse with the old rules. - Tests: the matrix is green; each parser's switch-off refusals, the environment values, and the Gemma and MiMo codec tests that pinned the refusals now pin the returned values. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… switch test of its own Behavior-preserving cleanup from the dedicated refactor pass: GLM5ToolCallParser's two copies of the seven JSON type names become jsonTypeNames; MiMoV2ToolCallParser's doc comment states its three value cases plainly; the environment checks of GrammarOnlyToolParsing leave the per-shape test for their own test. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…it read From the independent review of #434 + d-inference#2157: - GLM5ToolCallParser.argumentTypes reads anyOf/oneOf branch types, as MiMo does, so Pydantic's Optional[str] keeps 123, 1.0, true and "q" as text (finding 5). - Where no string is declared, a JSON value that is not a string keeps its JSON reading even if its type differs, so an integer-typed {"cmd":"x </arg_value> y"} is that object instead of a failed frame; a top-level JSON string is never kept, so it cannot run across frames (finding 2). - MiMoV2ToolCallParser reads every value it accepted before exactly as before and only reads the values it refused (unions, other types) as generated: a typeless nullable 1.0 stays "1.0" (finding 6). - Tests: the old fail-closed tables run against GLM5ToolCallParser (grammarOnly: false) (finding 4); Pydantic optional strings; the two value-boundary cases; MiMo values that parsed before. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…nion test
The header comment now says what the reader does since the review fixes
(JSON kept for a declared non-string type, or any non-string JSON where
no string is declared; types from argumentTypes). A test pins that a
string-or-null value split as {"a":" and "} across two frames reads as
two raw strings.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308
marked this pull request as ready for review
November 15, 2026 10:53
8 tasks done
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…434 Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…#434's merge) Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…434 Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…#434's merge) Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…434 Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…#434's merge) Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…434 Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…#434's merge) Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…434 Co-Authored-By: Claude <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 15, 2026
…#434's merge) Co-Authored-By: Claude <noreply@anthropic.com>
2 of 5 tasks
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.
Proposed changes
Fixes the SDK half of d-inference#2156: a GLM-5.3-Flash call that keeps the GLM grammar but omits a
requiredargument comes back from Darkbloom as raw<tool_call>text withfinish_reason: "stop", becauseGLM5ToolCallParserrefuses it. A matrix over every served format found the same class in two more parsers.GLM5ToolCallParserrequiredargument; undeclared argument (additionalPropertiesabsent orfalse); parameter without a usable type; union withstring; value of another typeauto: the whole trailing batch as text,finish_reason: stopGemmaFunctionParseradditionalProperties: falseauto: the frame as visible textMiMoV2ToolCallParser["string","integer"],anyOf); value of another typeauto: HTTP 500 (native MiMo tool output is invalid)The three parsers now check their frame grammar and the declared function name only and return such a call as generated, for the caller to validate, as vLLM and SGLang do. Declared types only choose how a value reads:
type,nullableandanyOf/oneOfbranches;GLM5ToolCallParser.argumentTypes(_:parameters:)exposes them so d-inference's tool-suffix lexer reads frame boundaries the same way): onlystring→ raw text; a JSON value of a declared non-string type, or any JSON but a string where nostringis declared → that JSON (quoted delimiters inside are data); anything else → JSON when its raw text (up to the first</arg_value>) parses (for a union withstring, only as one of the other types), else the raw text.stringis declared), else raw text.Frames that break the grammar still fail (open at the end, misplaced or nested tags, a repeated argument, an undeclared function name), and one such GLM5 frame still refuses the batch at EOS.
Kill switch:
DARKBLOOM_GRAMMAR_ONLY_TOOL_PARSING=0(off/false/no) restores the three parsers' schema refusals (GrammarOnlyToolParsing; each parser also takesgrammarOnly:ininit).Companion: d-inference#2157 (into
dev) pins this branch, decides GLM's trailing run call by call and forwards the switch. This PR is not to be merged intomainwithout the owner's OK; the 0.10.14 fold moves the d-inference pin to its merge commit.Review
Refactor pass and independent fresh-context review (separate sessions; the review fuzzed ~2M suffix/schema pairs against
main): 0 differences with the switch off, 0 changed values for calls the old parsers accepted. Its fixes arec6b31248,ebfd713fand (delta review nits)c85e84cf(union branch types, JSON kept for non-string types but never a top-level string, MiMo legacy-first, the old GLM refusal tables run withgrammarOnly: false).Validation (local, Xcode 27.2 / Swift 6.4.2, M3 Ultra)
881963e5(GLM5 tests) andcde37cd0(the format matrix,SchemaOnlyToolCallTests) failed before their fixes; the matrix onmain0ed99d07fails for GLM5 (every shape), Gemma (undeclared underadditionalProperties: false) and MiMo V2 (union, mismatched type), single and parallel.ebfd713f):swift test --filter 'MLXLMServerTests|\.UnitTests/|Tool'811 + 339 + 59 Swift Testing and the XCTest suites passed.scripts/check_forkdiff.pyOK. Formatting: Xcode 27.2swift formaton the changed Swift files (the Lint job's check).pre-commit run --all-filesalso reformats ~350 filesmaindoes not format; those changes were discarded.DevNet
d-inference#2157 (pinning
c85e84cf) is merged intodev→ DevNet0.10.13-dev.branch.188. W1 on pair-2: PASS, no defects — ON 330/330 single-Mac + 24/24 pair responses returned every schema-breaking call astool_calls(Gemma, GPT-OSS, Qwen 3.5-9B / 3.8, Bonsai; stream + non-stream);DARKBLOOM_GRAMMAR_ONLY_TOOL_PARSING=0brought Gemma's refusal back. GLM5/MiMo models were not loadable on that pair, so they ran on a 256 GB M5 Ultra (same DevNet build): GLM-5.3-Flash 110/110 and MiMo V2.6 90/90 with every schema-breaking call (the issue's repro, a parallel batch with one bad call, undeclared and mistyped arguments) returned astool_calls; with the switch off, GLM reproduced the issue's markup +finish_reason: stopbyte for byte and MiMo its 500.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.