Skip to content

fix: sanitize unescaped control characters in JSON tool call responses#15

Open
madrynweb wants to merge 1 commit into
ManningWorks:mainfrom
madrynweb:fix/tool-call-json-parsing
Open

fix: sanitize unescaped control characters in JSON tool call responses#15
madrynweb wants to merge 1 commit into
ManningWorks:mainfrom
madrynweb:fix/tool-call-json-parsing

Conversation

@madrynweb

Copy link
Copy Markdown

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 \t
inside string values instead of properly escaped \\n, \\r, \\t.
This caused JSON.parse to fail silently, so tool calls were never processed.

Fix

  • Added sanitizeJsonString() to escape control characters only when
    detected inside JSON strings (doesn't break already-valid escapes).
  • Improved brace counting in parseTextFormat to respect string
    boundaries — no longer confuses {/} inside string values.
  • Added graceful recovery: if one tool call fails to parse, it continues
    to the next TOOL_CALL instead 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.

  • base repository: ManningWorks/DOAI-Proxy
  • base: main
  • head repository: madrynweb/DOAI-Proxy
  • compare: fix/tool-call-json-parsing

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.
@vercel

vercel Bot commented May 22, 2026

Copy link
Copy Markdown

@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.

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.

1 participant