← Back to PRs

#20534: fix: handle malformed tool call JSON parse errors gracefully

by echoVic open 2026-02-19 02:14 View on GitHub →
agents size: S
## Problem Fixes #7867 When a model (e.g. Venice.ai Kimi K2.5) produces malformed tool call arguments — such as concatenated JSON `{}{"path":...}` — the JSON parse `SyntaxError` is surfaced verbatim to the user via the messaging channel: > Unexpected non-whitespace character after JSON at position 2 (line 1 column 3) This is confusing and leaks internal implementation details. ## Solution Add `isMalformedToolCallError()` in `formatAssistantErrorText()` to detect common JSON `SyntaxError` patterns (unexpected token, unterminated string, etc.) and rewrite them to a user-friendly message: > The model produced a malformed tool call that couldn't be parsed. Please try again — if this persists, switch to a different model or use /new to start a fresh session. ## Related - #16673 (centralized outbound sanitization gate) - #9951 (context overflow errors leak) - #18937 (API error messages leak) <!-- greptile_comment --> <h3>Greptile Summary</h3> Added detection and user-friendly formatting for malformed tool call JSON parse errors. When models like Venice.ai Kimi K2.5 produce invalid JSON (e.g., concatenated objects `{}{"path":...}`), the system now shows a helpful message instead of exposing raw `SyntaxError` details to users. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with minimal risk - it adds defensive error handling for a specific edge case - The change is small, focused, and defensive in nature. It improves user experience by sanitizing internal error messages. The regex pattern could theoretically have false positives, but given the context (error messages from LLM APIs), this is unlikely to cause issues in practice. The only concern is the lack of tests for the new functionality. - No files require special attention <sub>Last reviewed commit: 04d2107</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs