Reject null input in agent tool parameter validation

JSON null unmarshals into an empty string, so the presence-only
key check let {"input":null} through, running the nested agent
with a blank user message.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-13 19:57:18 +01:00
parent 9d999559f1
commit d80a0fa7e4
2 changed files with 23 additions and 1 deletions

View File

@@ -83,7 +83,8 @@ func (t *agentTool) Execute(ctx context.Context, arguments string) (ToolResult,
}, nil
}
if _, ok := fields["input"]; !ok {
raw, ok := fields["input"]
if !ok || string(raw) == "null" {
return ToolResult{
Content: "Missing required parameters: input",
IsError: true,

View File

@@ -215,6 +215,27 @@ func TestAgentTool_Execute(t *testing.T) {
},
)
t.Run(
"null input returns tool error for missing input",
func(t *testing.T) {
t.Parallel()
ag := agent.New(
"sub",
newTestClient(&mockProvider{}),
agent.WithModel("test-model"),
)
tool := ag.AsTool("sub_tool", "A sub-agent tool.")
result, err := tool.Execute(context.Background(), `{"input":null}`)
require.NoError(t, err)
assert.True(t, result.IsError)
assert.Contains(t, result.Content, "Missing required parameters")
assert.Contains(t, result.Content, "input")
},
)
t.Run(
"sub-agent error propagates as Go error",
func(t *testing.T) {