common : fix tool call type detection for nullable and enum schemas#21327
Conversation
|
Yes I'll test it tomorrow |
|
This should be common functionality implemented in |
|
Thanks for looking at this. @aldehir good call - I didn't realize I'll rework it to add a type name getter (or similar) to One thing I want to check: for the enum case where there's no explicit |
|
It does infer types if there is no I might have jumped the gun and perhaps this surgical change might be good for now and we can address the general case later. |
…add tests
Fix enum type inference to scan all enum values (not just index 0) so
schemas like {"enum": [0, "celsius"]} correctly detect string type.
Fix schema_delegates in peg-parser to handle nullable type arrays
(["string", "null"]) and typeless enum schemas in raw mode, allowing
the tagged parser to use raw text instead of JSON-formatted strings.
Add test cases for Qwen3-Coder (TAG_WITH_TAGGED format):
- nullable string ["string", "null"]
- nullable string with null first ["null", "string"]
- nullable integer ["integer", "null"]
- enum without explicit type key
|
I wasn't been able to test this on my side, but the added case in |
pwilkin
left a comment
There was a problem hiding this comment.
I'd say we utilize this fix now and possibly generalize later.
Includes: - server: Fix undefined timing measurement errors (ggml-org#21201) - server: save and clear idle slots on new task --clear-idle (ggml-org#20993) - common: fix tool call type detection for nullable/enum schemas (ggml-org#21327) - CUDA: fix FA kernel selection logic (ggml-org#21271) - kv-cache: do not quantize SWA KV cache (ggml-org#21277) + revert (ggml-org#21332) - common/parser: fix call ID detection + atomicity (ggml-org#21230) - jinja: coerce input for string-specific filters (ggml-org#21370) - Various CI, HIP, WebGPU, and documentation fixes
Overview
Fixes #21316
The Gemma4 dict parser and the tagged parser both only check
type_v.is_string()when figuring out if a tool argument is a string. This breaks for schemas that use nullable types like"type": ["string", "null"]or enum fields without an explicit"type"key, both of which are pretty common in OpenAPI/Home Assistant setups.When the type isn't recognized as
"string", the parser falls through to the raw-value path and captures<|"|>delimiter tokens as literal text, which is how you end up with output like"domain": "[<|\"|>light<|\"|>]"instead of"domain": "light".The fix is straightforward:
enumfields that have string valuesbuild_tool_parser_tag_gemma4_dictandbuild_tool_parser_tag_taggedsince they share the same patternAll existing tests pass (
test-chat-auto-parser: 56 tests, 373 assertions, 0 failures;test-chat: all passed).Requirements