fix(chat): graceful degradation for malformed tool call arguments#22089
Open
huckstack wants to merge 1 commit intoggml-org:masterfrom
Open
fix(chat): graceful degradation for malformed tool call arguments#22089huckstack wants to merge 1 commit intoggml-org:masterfrom
huckstack wants to merge 1 commit intoggml-org:masterfrom
Conversation
Replace throw with LOG_WRN in func_args_not_string() to prevent HTTP 500 errors when models generate malformed JSON in tool call arguments (e.g., unescaped single quotes). The function was introduced in commit b283f6d with throw, which causes cascading failures where every subsequent request crashes with 'Failed to parse tool call arguments as JSON'. Fix: catch the exception and log a warning instead of throwing. The arguments are kept as a string, allowing the conversation to continue.
|
Hi @huckstack, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
Contributor
|
Unfortunately, this is not sufficient. Some chat templates require Do you have a reliable reproducer I can run? Fixing the core issue is the solution here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When models generate malformed JSON in tool call arguments (e.g., unescaped single quotes like
log_dir = '/home/huckstack/.hermes/logs/cron'),func_args_not_string()throws an HTTP 500 error. This causes cascading failures where every subsequent request crashes withFailed 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 std::runtime_error(...)withLOG_WRN(...)infunc_args_not_string(). This converts the hard 500 error into a graceful degradation — the server logs a warning and keeps the arguments as a string, allowing the conversation to continue.Context
This is related to issue #21771 which reports the same symptom. The root cause there is the PEG parser failing on
array<object>parameter values, but the symptom (HTTP 500 fromfunc_args_not_string) is the same. This fix addresses the symptom by making the error handling more robust.Diff