Skip to content

fix(chat): graceful degradation for malformed tool call arguments (v2)#22115

Closed
huckstack wants to merge 1 commit intoggml-org:masterfrom
huckstack:fix/graceful-tool-call-args-v2
Closed

fix(chat): graceful degradation for malformed tool call arguments (v2)#22115
huckstack wants to merge 1 commit intoggml-org:masterfrom
huckstack:fix/graceful-tool-call-args-v2

Conversation

@huckstack
Copy link
Copy Markdown

DISCLOSURE

This contribution was developed by a human (David @ huckstack) with assistance from an AI coding agent (Hermes). The human reviewed and approved all changes.

Problem

When models generate malformed JSON in tool call arguments (e.g., unescaped single quotes like log_dir = '/home/user/.hermes/logs/cron'), func_args_not_string() throws an HTTP 500 error. This causes cascading failures where every subsequent request crashes with Failed to parse tool call arguments as JSON: unexpected end of input.

The function was introduced in commit b283f6d with throw, which converts a recoverable parsing error into a hard server error.

Fix

Replace throw with LOG_WRN in func_args_not_string(). This converts the hard 500 error into graceful degradation — the server logs a warning and keeps the arguments as a string, allowing the conversation to continue.

Context

This is a pragmatic workaround, not a root fix. The core issue is that the PEG parser in the TAG_WITH_TAGGED tool format (introduced by PR #21216) fails on malformed JSON in parameter values. See issue #21771 for the full analysis of the parser regression.

Related: #21771, #22072, #12068 (hermes-agent)

Testing

This fix has been validated on:

  • Pop!_OS with llama.cpp b8833
  • Qwen3.6-35B-A3B local endpoint
  • RTX 3060 (12GB VRAM)

The fix prevents the HTTP 500 cascade while allowing the conversation to continue. The warning is logged for debugging purposes.

DISCLOSURE: This patch was developed by a human (David @ huckstack) with
assistance from an AI coding agent (Hermes). The human reviewed and
approved all changes.

Problem:
When models generate malformed JSON in tool call arguments (e.g.,
unescaped single quotes like log_dir = '/home/user/.hermes/logs/cron'),
func_args_not_string() throws an HTTP 500 error. This causes cascading
failures where every subsequent request crashes with
'Failed to parse tool call arguments as JSON: unexpected end of input'.

The function was introduced in commit b283f6d with throw, which
converts a recoverable parsing error into a hard server error.

Fix:
Replace throw with LOG_WRN in func_args_not_string(). This converts the
hard 500 error into graceful degradation — the server logs a warning and
keeps the arguments as a string, allowing the conversation to continue.

Note: This is a pragmatic workaround, not a root fix. The core issue is
that the PEG parser in the TAG_WITH_TAGGED tool format (introduced by
PR ggml-org#21216) fails on malformed JSON in parameter values. See issue ggml-org#21771
for the full analysis of the parser regression.

Related: ggml-org#21771

Signed-off-by: David @ huckstack <huckstack@gmail.com>
@CISC
Copy link
Copy Markdown
Member

CISC commented Apr 19, 2026

Duplicate of #22089

@CISC CISC marked this as a duplicate of #22089 Apr 19, 2026
@CISC CISC closed this Apr 19, 2026
@ggml-gh-bot
Copy link
Copy Markdown

ggml-gh-bot Bot commented Apr 19, 2026

Hi @huckstack, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

  • AI-generated content: This project does not accept PRs, descriptions or commit messages that are fully or predominantly AI-generated. If you have used AI to assist you in writing code, please make sure to disclose that explicitly.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

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.

2 participants