Sanitize malformed tool-call inputs before sending agent history to Anthropic#2378
Sanitize malformed tool-call inputs before sending agent history to Anthropic#2378RNViththagan wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughA new ChangesTool-call input sanitization for Anthropic compatibility
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Related to wso2/product-integrator#1741
Sometimes a tool call's input comes back as a string instead of an object — the SDK keeps the raw text when the JSON is invalid. Anthropic then rejects every following request in that chat with
tool_use.input: Input should be an object, leaving the thread permanently stuck.This is a workaround for the issue at the client side — it sanitizes the history before sending it to the provider so already-poisoned threads stop 400-ing. The root cause (the model producing invalid JSON for the tool call) is a separate follow-up.
sanitizeMessages, which fixes up any such tool-call input (parse it if possible, otherwise drop it to{}) before history is sent to the modelSummary by CodeRabbit
New Features
Tests