Skip to content

chat : enforce string enums in Qwen XML tool arguments - #26

Open
arc-uri-el wants to merge 1 commit into
halo-box:masterfrom
arc-uri-el:fix/qwen-string-enums-halo
Open

chat : enforce string enums in Qwen XML tool arguments#26
arc-uri-el wants to merge 1 commit into
halo-box:masterfrom
arc-uri-el:fix/qwen-string-enums-halo

Conversation

@arc-uri-el

Copy link
Copy Markdown

Overview

The Qwen XML tool grammar accepts arbitrary strings for a parameter declared as {"type":"string","enum":["list","load"]}. For example, <parameter=action>\nerase\n</parameter> is accepted even though erase is not an allowed value.

The handler selects its unrestricted XML string rule whenever the parameter resolves to a string. It therefore bypasses the JSON converter that would enforce the enum for JSON arguments.

For a nonempty string enum, build the XML value rule from the allowed literal strings instead. Check the closing-parameter boundary when choosing each literal, so an earlier shorter entry does not consume the prefix of a longer one. Ordinary strings and non-string enums retain their existing paths. This patch adds no root-union support, schema adapter, public API, model or GPU change.

Additional information

Validation

Base: 33870a2e1c99419041ae57f838db0ba3f9d6a122.

Separate matching baseline/candidate Linux x86_64 builds used GCC 15.2, Release, shared libraries, native CPU and OpenMP. All seven selected parser/grammar suites passed on both builds, with zero compiler warnings: test-chat, test-json-schema-to-grammar, test-chat-peg-parser, test-chat-auto-parser, test-chat-template, test-grammar-parser and test-grammar-integration.

The exact new test-chat binary fails against baseline libraries at the invalid-enum assertion (expected rejection, observed acceptance) and passes against candidate libraries. The added test covers Qwen3-Coder and Qwen3.5 templates, invalid strings, shared-prefix alternatives, empty strings, embedded quotes/newlines, parsed/streamed tool arguments, parallel calls and an unrestricted-string positive control.

This replaces the broader root-union proposal in #25. That representation can be adapted on the client side; ordinary enum enforcement is an independent defect.

Not run for this isolated patch: model inference, full CI, other-platform builds, perplexity or performance sweeps. No throughput or general model-quality improvement is claimed.

Requirements

  • I have read and agree with the contributing guidelines.
  • This is a human-directed contribution. I own its review follow-up.
  • AI usage disclosure: YES. GPT-6 Astra assisted with investigation, code and regression tests, execution, evidence analysis and submission preparation. No independent human code-review attestation is claimed.

Use allowed XML literals instead of the unrestricted string production. Require the parameter-close boundary when matching alternatives with shared prefixes. Cover rejected values, empty and escaped strings, parsing, streaming and ordinary-string behavior in the existing chat suite.

Assisted-by: GPT-6 Astra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant