{"record":{"id":"e1a959d015516467","repo":"siyuan-note/siyuan","slug":"invalid-tool-arguments-w-e1a959","errorCode":null,"errorMessage":"invalid tool arguments: %w","messagePattern":"invalid tool arguments: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/tools.go","lineNumber":51,"sourceCode":"\tModelAttachments []tools.ModelAttachment\n\tIsError          bool\n\tExecutionUnknown bool\n}\n\n// validateToolCallInput 在确认和快照之前校验工具调用，避免无效调用被误判为写操作。\nfunc validateToolCallInput(ctx context.Context, toolName string, args map[string]any) (*tools.Tool, *tools.ToolValidator, error) {\n\tt, validator := tools.LookupToolWithValidator(toolName)\n\tif t == nil {\n\t\treturn nil, nil, fmt.Errorf(\"unknown tool: %s\", toolName)\n\t}\n\tif t.ContextHandler == nil && t.Handler == nil {\n\t\treturn nil, nil, fmt.Errorf(\"tool handler unavailable: %s\", toolName)\n\t}\n\tif ctx.Err() != nil {\n\t\treturn nil, nil, fmt.Errorf(\"tool execution was cancelled before it started\")\n\t}\n\tif err := validator.ValidateInputContext(ctx, args); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"invalid tool arguments: %w\", err)\n\t}\n\treturn t, validator, nil\n}\n\nfunc validateCapabilityCall(ctx context.Context, registration *capabilityRegistration, args map[string]any) error {\n\tif registration == nil {\n\t\treturn fmt.Errorf(\"capability was not exposed in this model round\")\n\t}\n\tif !capabilityStillExecutable(registration, args) {\n\t\treturn fmt.Errorf(\"capability is disabled or no longer available: %s\", registration.ID)\n\t}\n\tif ctx.Err() != nil {\n\t\treturn fmt.Errorf(\"capability execution was cancelled before it started\")\n\t}\n\tif registration.Validator == nil {\n\t\treturn fmt.Errorf(\"capability validator unavailable: %s\", registration.ID)\n\t}\n\tif err := registration.Validator.ValidateInputContext(ctx, args); err != nil {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/agent/tools.go#L33-L69","documentation":"After the tool is found and the context is live, validateToolCallInput runs validator.ValidateInputContext(ctx, args) against the tool's input schema. Any schema validation failure (missing required fields, wrong types, invalid enum values in args) is wrapped as 'invalid tool arguments' with the underlying cause preserved via %w.","triggerScenarios":"Calling a tool with args that violate its declared schema: missing a required 'action' field, wrong value types (string vs number), unknown enum values, or extra fields when strict validation applies.","commonSituations":"LLM produces incomplete or mistyped tool arguments; caller builds args map manually and forgets a required key (e.g. the missing 'action' covered by the related test); schema evolved and older callers still send the previous shape.","solutions":["Read the wrapped cause for the exact field/path that failed and fix the args accordingly","Ensure all required fields per the tool schema (e.g. 'action') are present before calling","Regenerate or update callers after tool schema changes so argument shapes stay in sync","Validate the args map client-side against the same schema before dispatching"],"exampleFix":"// before: missing required 'action' argument\nargs := map[string]any{\"path\": \"/tmp/a.txt\"}\nvalidateToolCallInput(ctx, \"write_file\", args)\n// after\nargs := map[string]any{\"path\": \"/tmp/a.txt\", \"action\": \"write\"}\nvalidateToolCallInput(ctx, \"write_file\", args)","handlingStrategy":"validation","validationCode":"if _, ok := args[\"action\"]; !ok {\n    return errors.New(\"missing required tool argument: action\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"invalid tool arguments:\") {\n    var verr error\n    errors.As(err, &verr) // unwrap for the exact schema path/field\n    return fmt.Errorf(\"fix arguments before retrying: %w\", verr)\n}","preventionTips":["Validate tool arguments against the tool schema before dispatching","Keep client-side arg construction in sync with schema changes","Log full args (minus sensitive data) when validation fails to spot missing fields"],"tags":["agent","tools","validation","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}