server: restore schema-declared argument types for GLM tool calls#571
Open
solodddd wants to merge 1 commit into
Open
server: restore schema-declared argument types for GLM tool calls#571solodddd wants to merge 1 commit into
solodddd wants to merge 1 commit into
Conversation
GLM's tool-call wire format (<arg_key>k</arg_key><arg_value>v</arg_value>)
carries no type information, so the parser stored every argument as a JSON
string ("max_results":"10"), breaking clients that validate tool-call
arguments against the tool schema (zod/ajv etc).
Capture each property's declared "type" while parsing tool schemas, and
restore non-string types at client serialization time: a string value whose
declared type is number/integer/boolean/array/object/null and whose text is
valid JSON of that kind is emitted raw. Values that don't cleanly match
their declared type, undeclared properties, and untyped schemas keep the
current stringly behavior. Covers chat completions (final + deltas),
Responses, and Anthropic outputs.
Fixes antirez#569
Co-Authored-By: Claude Fable 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 #569.
Problem
On the
glm5.2branch, the GLM tool-call parser stores every<arg_key>/<arg_value>argument as a JSON string ("max_results":"10","exclude_domains":"[]"), because GLM's wire format carries no type information — unlike DeepSeek's DSMLstring="true|false"attribute. Clients that validate tool-call arguments against the tool's JSON schema (Chatwise and anything zod/ajv-based) reject every call with a non-string parameter.Fix
Schema-aware type restoration, no heuristics:
"type"alongside the existing property-order bookkeeping (tool_schema_ordergains a parallelprop_typearray).number/integer/boolean/array/object/nulland whose text is exactly one valid JSON value of that kind is emitted raw; everything else (declared strings, undeclared properties, values that don't match their declared type, untyped/union schemas) keeps the current behavior.tool_useblocks (final + SSE flush). Prompt re-rendering paths are untouched. DeepSeek DSML calls are unaffected (their values are already typed; the coercion only ever unquotes a string whose schema says non-string).Tests
Added
test_openai_tool_args_restore_schema_typescovering: number/boolean/array restoration, declared strings staying strings, undeclared properties staying strings, and a value that is not valid JSON of its declared type staying a string.Per CONTRIBUTING:
GLM-5.2-UD-Q4_K_RoutedQ4K.gguf).make— clean build, no new warnings../ds4_test— all tracks pass (including--server, which covers the tool-call parsing/serialization touched here).Before:
After (same request, tool schema declares
max_results: number,exclude_domains: array):No inference backend is touched — the change is confined to request-schema parsing and response serialization — so there is no speed-regression surface.
Developed with the assistance of Claude (Anthropic), reviewed and tested by me.