Skip to content

feat: exclude control markers from Kimi-K3 tool-argument strings - #915

Merged
Seven-Streams merged 4 commits into
mlc-ai:mainfrom
Seven-Streams:split901/5-kimi-k3-excludes
Sep 21, 2026
Merged

Seven-Streams merged 4 commits into
mlc-ai:mainfrom
Seven-Streams:split901/5-kimi-k3-excludes

Conversation

@Seven-Streams

Copy link
Copy Markdown
Member

Extracted from #901 by @izhuhaoran, last piece after #906, #909, #910 and #912. The branch keeps the original commit and its revert at the bottom for attribution; the net diff against main is the feat(kimi_k3): exclude control markers from tool-argument strings commit plus a docs commit that states the exclusion rules of #912 as a list.

What changes

The Kimi-K3 builtin now passes excludes=["<|open|>", "<|cloase|>", "<|sep|>"] to the JSONSchemaFormat of every tool-argument schema, in auto, required and forced tool modes. A control marker inside a raw string argument is rejected at the mask instead of being swallowed as text, which is the original #901 bad case: the model emitted <|close|>response<|sep|> inside an open response argument and started another tools/call block. The existing exclude_special_tokens=False option disables this together with the free-text exclusions; the free-text reasoning/response scope is unchanged.

Per #912, the exclusions apply to argument strings without pattern/format and to property names, nested JSON strings included; minLength/maxLength on such strings are dropped with a warning. Argument and call wrappers are outside the scope, so <|close|>argument<|sep|> still terminates a value.

web/src/structural_tag.ts gains the kimi_k3_xml member of the JSONSchemaFormat.style union, missed when the style was introduced in #806.

Validation

  • tests/python/test_builtin_structural_tag.py: the instance that accepted a complete <|close|>response<|sep|> inside a string argument now expects rejection (malformed-argument-end-in-string); test_kimi_k3_exclude_special_tokens checks the three exclusions on every tool-argument schema across the three tool-choice modes and the opt-out; test_kimi_k3_tool_argument_exclusions covers raw and nested JSON string values with and without the option, including complete valid argument and call endings.
  • test_builtin_structural_tag, test_json_schema_excludes, test_structural_tag_converter: 1733 passed. The C++ tree is identical to main. Full tests/python with HF_TOKEN: 4946 passed, 3 skipped; the only failures are the CUDA kernel tests that JIT-build a torch extension, which fail identically on main in this environment (CUDA 11.1 toolkit).

izhuhaoran and others added 3 commits September 21, 2026 14:35
Signed-off-by: zhuhaoran <zhuhaoran.zhr@alibaba-inc.com>
This reverts commit d62c120.

The change is re-applied in separate commits so that the FSM state-limit
fix, the Unicode character class fix, the regular-grammar flattener, the
excludes feature, and the Kimi-K3 wiring can be reviewed independently.
The Kimi-K3 builtin now supplies JSONSchemaFormat.excludes with
<|open|>, <|close|>, and <|sep|> for every tool-argument schema in auto,
required, and forced tool modes, so a control marker inside a raw string
argument is rejected at the mask instead of being swallowed as text.
The existing exclude_special_tokens=False option disables this filter;
free-text reasoning/response exclusions keep their current scope.

The builtin test that accepted a complete <|close|>response<|sep|>
inside a string argument now expects rejection, and new tests cover the
default exclusions and opt-out across the three tool-choice modes, raw
and nested JSON strings, and complete valid argument/call endings.

Also add the kimi_k3_xml style to the TypeScript JSONSchemaFormat type,
which was missed when the style was introduced.

Extracted from mlc-ai#901.
Copilot AI lite review requested due to automatic review settings September 21, 2026 18:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…ing rules

Per mlc-ai#912, excludes apply to the string values without pattern/format and
to property names; minLength/maxLength are dropped with a warning and
const/enum alternatives containing an excluded substring are removed.
Say so in the structural tag docs, the JSONSchemaFormat docstring and the
Kimi-K3 builtin docstrings, which still claimed every string value.
@Seven-Streams
Seven-Streams force-pushed the split901/5-kimi-k3-excludes branch from aa342e4 to 9274b9f Compare September 21, 2026 19:43
@Seven-Streams
Seven-Streams merged commit 40ef651 into mlc-ai:main Sep 21, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants