Skip to content

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

Merged
dzannotti merged 1 commit into
halo-box:masterfrom
arc-uri-el:fix/qwen-string-enums-halo
Sep 15, 2026
Merged

dzannotti merged 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.

@dzannotti

Copy link
Copy Markdown

@arc-uri-el LGTM, but it has conflicts, would you mind rebasing?

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
@arc-uri-el
arc-uri-el force-pushed the fix/qwen-string-enums-halo branch from fe2e057 to 155cfcb Compare September 15, 2026 11:07
@arc-uri-el

Copy link
Copy Markdown
Author

Rebased onto current halo-box:master and force-pushed the updated branch. The parser change is now in common/parsers/qwen3-coder.cpp after the upstream parser split. A fresh Release shared-library build of test-chat with GCC 15.2 completed, and the full test-chat suite passed.

@dzannotti
dzannotti merged commit e20d6f5 into halo-box:master Sep 15, 2026
1 check passed
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.

2 participants