fix: sanitize unescaped control characters in JSON tool call responses#15
Open
madrynweb wants to merge 1 commit into
Open
fix: sanitize unescaped control characters in JSON tool call responses#15madrynweb wants to merge 1 commit into
madrynweb wants to merge 1 commit into
Conversation
The provider sometimes returns JSON with literal \n, \r, and \t inside string values instead of escaped \\n, \\r, \\t. This caused JSON.parse to fail silently, so tools (function calling) were shown as text in the chat instead of being executed. Added sanitizeJsonString() to escape control characters only when inside JSON strings. Also improved brace counting to respect string boundaries and added graceful recovery when a tool call fails to parse.
|
@madrynweb is attempting to deploy a commit to the reallukemanning's projects Team on Vercel. A member of the Team first needs to authorize it. |
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 using DOAI-Proxy with Kilo Code (VS Code extension), the AI responses
showed function calls as raw text in the chat instead of executing them.
The tools never modified files.
Root Cause
The provider sometimes returns JSON with literal
\n,\r, and\tinside string values instead of properly escaped
\\n,\\r,\\t.This caused
JSON.parseto fail silently, so tool calls were never processed.Fix
sanitizeJsonString()to escape control characters only whendetected inside JSON strings (doesn't break already-valid escapes).
parseTextFormatto respect stringboundaries — no longer confuses
{/}inside string values.to the next
TOOL_CALLinstead of aborting everything.Testing
Tested with Kilo Code extension. Function calling now executes properly
and modifies files as expected.
Note: This fix was developed with AI assistance. I'm open to any
suggestions or improvements.
ManningWorks/DOAI-Proxymainmadrynweb/DOAI-Proxyfix/tool-call-json-parsing