Skip to content

fix(parsers): preserve literal entities in GLM-4.7 arguments - #286

Closed
qimcis wants to merge 1 commit into
ai-dynamo:mainfrom
qimcis:fix/glm47-literal-entities
Closed

qimcis wants to merge 1 commit into
ai-dynamo:mainfrom
qimcis:fix/glm47-literal-entities

Conversation

@qimcis

@qimcis qimcis commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Description

The v1 GLM-4.7 parser decodes < > & " ' in every tool-call argument value, so when the model writes an entity on purpose, the client gets the raw character instead. Found this to be an issue when we were serving glm-5.3 and seeing agents writing python and html, e.g. cleaning up scraped HTML:

generated: txt = re.sub(r""", '"', txt)
delivered: txt = re.sub(r""", '"', txt)    -> SyntaxError: unterminated triple-quoted string literal

and attributes like title="He said "hi" & waved 'bye'." come through as title="He said "hi" & waved 'bye'.". In this case, the decoded value is still a valid string, so nothing errors on the serving side and it only shows up downstream

the main cause is decode_xml_entities in parse_tool_call_block, where the glm chat template writes string arguments into <arg_value> raw (only non-strings go through tojson), so there is no escaping layer to undo: the text between the markers already is the value.

This removes the decode, passes raw_value straight to coerce_value, and flips the existing test_xml_entity_decoding into test_xml_entities_kept_verbatim. This matches the v2 parser after #249 as well as vLLM's and SGLang's GLM-4.7 parsers, which also keep entities verbatim

@qimcis
qimcis requested a review from a team as a code owner September 24, 2026 18:16
@copy-pr-bot

copy-pr-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added fix external-contribution PR originates from a fork labels Sep 24, 2026
@qimcis
qimcis force-pushed the fix/glm47-literal-entities branch from a2ddb44 to 59c50ab Compare September 24, 2026 22:50
Signed-off-by: Chi McIsaac <chixie.mcisaac@gmail.com>
@qimcis
qimcis force-pushed the fix/glm47-literal-entities branch from 59c50ab to 01e004a Compare September 24, 2026 22:51
@qimcis

qimcis commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

PR redundant now, as change is now in #290

@qimcis qimcis closed this Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution PR originates from a fork fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant