fix: return isError for argument validation failures#2488
Open
blackwell-systems wants to merge 1 commit into
Open
fix: return isError for argument validation failures#2488blackwell-systems wants to merge 1 commit into
blackwell-systems wants to merge 1 commit into
Conversation
When tool argument unmarshalling fails (wrong types, malformed JSON),
return a tool execution error (isError: true) instead of a Go error
that becomes a protocol error (-32603). This allows agents to see the
validation error message in their context window and self-correct.
Previously, an agent sending {"owner": 12345} (integer) instead of
{"owner": "octocat"} (string) would get an opaque -32603 protocol
error with no message. Now it gets isError: true with
"invalid arguments: json: cannot unmarshal number..." which the model
can act on.
Two sites fixed in server_tool.go:
- NewServerTool (deps-based handler wrapper)
- NewServerToolWithContextHandler (context-based handler wrapper)
Tests added:
- TestNewServerTool_InvalidArguments_ReturnsIsError
- TestNewServerToolWithContextHandler_InvalidArguments_ReturnsIsError
- TestNewServerTool_ValidArguments_Succeeds
Fixes github#1952
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.
Fixes #1952.
Problem
When tool argument unmarshalling fails (wrong types, malformed JSON), the handler returns
(nil, err)which the SDK converts to a JSON-RPC protocol error (-32603). Agents cannot see protocol errors in their context window, so they cannot self-correct.Fix
Return
isError: truewith the validation error message instead of a Go error. Two sites inserver_tool.go:NewServerTool(line 135)NewServerToolWithContextHandler(line 159)Before:
After:
Tests
TestNewServerTool_InvalidArguments_ReturnsIsErrorTestNewServerToolWithContextHandler_InvalidArguments_ReturnsIsErrorTestNewServerTool_ValidArguments_Succeeds