Skip to content

Sanitize JSON tool-call payload text#14098

Open
helloember99 wants to merge 1 commit intoopenclaw:mainfrom
helloember99:fix/strip-json-tool-calls
Open

Sanitize JSON tool-call payload text#14098
helloember99 wants to merge 1 commit intoopenclaw:mainfrom
helloember99:fix/strip-json-tool-calls

Conversation

@helloember99
Copy link

@helloember99 helloember99 commented Feb 11, 2026

Summary

  • add stripJsonToolCallText helper to remove raw tool-call JSON payloads before they reach user surfaces
  • call the helper from extractAssistantText, sanitizeTextContent, and the streaming pipeline so Ollama/local providers can no longer leak blobs when tool downgrades happen
  • add regression tests covering the helper and ensuring extractAssistantText drops JSON payloads but retains normal JSON blobs

Testing

  • corepack pnpm vitest run src/agents/pi-embedded-utils.test.ts

Greptile Overview

Greptile Summary

Adds defense against raw JSON tool-call payload leakage in text content. When local/Ollama providers downgrade tool calls to text (due to incompatibility or errors), the raw JSON can leak into user-facing surfaces. This PR introduces stripJsonToolCallText() helper that detects and removes JSON objects/arrays matching tool-call structure (having name + one of: arguments, args, input, tool_input, parameters, payload). The helper is integrated into the streaming pipeline (pi-embedded-subscribe.ts), text extraction (extractAssistantText), and message sanitization (sanitizeTextContent). Test coverage includes both removal of tool payloads and preservation of legitimate JSON blobs.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is defensive and well-tested. The helper function includes both strict JSON parsing validation and a fallback regex pattern. All integration points (streaming, extraction, sanitization) are covered. Test cases verify both positive (removing tool payloads) and negative (preserving legitimate JSON) scenarios. The change only affects text sanitization paths and cannot break tool call functionality.
  • No files require special attention

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments