{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/agent/tools.go#L33-L69","documentation":"The tool's ToolValidator rejected the supplied arguments: validator.ValidateInputContext returned an error, and validateToolCallInput wraps it with \"invalid tool arguments: %w\". The original validator message is preserved via %w, so errors.Is/As still work on the wrapped cause.","triggerScenarios":"Calling validateToolCallInput with an args map that fails the tool's input schema — missing a required property, wrong JSON type, value outside allowed range, or failing a custom context-aware validation rule.","commonSituations":"The model emits arguments not matching the declared JSON schema (e.g. string where number expected); a caller builds args programmatically with wrong keys; a schema was tightened but old prompts still elicit the old argument shape.","solutions":["Read the wrapped cause (%w) to see which property failed, then correct the args map to match the tool's schema.","Regenerate or constrain the model so it emits arguments conforming to the current tool schema.","Update the prompt/system message if the tool's parameter schema changed recently."],"exampleFix":"// before\nargs := map[string]any{\"path\": 123}\n// after\nargs := map[string]any{\"path\": \"/tmp/note.md\"}","handlingStrategy":"validation","validationCode":"if err := validator.ValidateInputContext(ctx, args); err != nil {\n    return fmt.Errorf(\"pre-flight args check failed: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"var invalidArgsErr *tools.ValidationError\nif _, _, err := validateToolCallInput(ctx, name, args); err != nil {\n    if errors.As(err, &invalidArgsErr) { /* repair args or re-prompt */ }\n}","preventionTips":["Publish the exact JSON schema to the model and regenerate schemas after changes","Validate programmatically built args against the tool schema before dispatch","Keep prompts in sync with tightened schemas"],"tags":["validation","schema","arguments"],"backgroundTag":"schema-validation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}