siyuan-note/siyuan · error

invalid tool arguments: %w

Error message

invalid tool arguments: %w

What it means

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.

Source

Thrown at kernel/agent/tools.go:51

	ModelAttachments []tools.ModelAttachment
	IsError          bool
	ExecutionUnknown bool
}

// validateToolCallInput 在确认和快照之前校验工具调用,避免无效调用被误判为写操作。
func validateToolCallInput(ctx context.Context, toolName string, args map[string]any) (*tools.Tool, *tools.ToolValidator, error) {
	t, validator := tools.LookupToolWithValidator(toolName)
	if t == nil {
		return nil, nil, fmt.Errorf("unknown tool: %s", toolName)
	}
	if t.ContextHandler == nil && t.Handler == nil {
		return nil, nil, fmt.Errorf("tool handler unavailable: %s", toolName)
	}
	if ctx.Err() != nil {
		return nil, nil, fmt.Errorf("tool execution was cancelled before it started")
	}
	if err := validator.ValidateInputContext(ctx, args); err != nil {
		return nil, nil, fmt.Errorf("invalid tool arguments: %w", err)
	}
	return t, validator, nil
}

func validateCapabilityCall(ctx context.Context, registration *capabilityRegistration, args map[string]any) error {
	if registration == nil {
		return fmt.Errorf("capability was not exposed in this model round")
	}
	if !capabilityStillExecutable(registration, args) {
		return fmt.Errorf("capability is disabled or no longer available: %s", registration.ID)
	}
	if ctx.Err() != nil {
		return fmt.Errorf("capability execution was cancelled before it started")
	}
	if registration.Validator == nil {
		return fmt.Errorf("capability validator unavailable: %s", registration.ID)
	}
	if err := registration.Validator.ValidateInputContext(ctx, args); err != nil {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Read the wrapped cause (%w) to see which property failed, then correct the args map to match the tool's schema.
  2. Regenerate or constrain the model so it emits arguments conforming to the current tool schema.
  3. Update the prompt/system message if the tool's parameter schema changed recently.

Example fix

// before
args := map[string]any{"path": 123}
// after
args := map[string]any{"path": "/tmp/note.md"}
Defensive patterns

Strategy: validation

Validate before calling

if err := validator.ValidateInputContext(ctx, args); err != nil {
    return fmt.Errorf("pre-flight args check failed: %w", err)
}

Try / catch

var invalidArgsErr *tools.ValidationError
if _, _, err := validateToolCallInput(ctx, name, args); err != nil {
    if errors.As(err, &invalidArgsErr) { /* repair args or re-prompt */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/e1a959d015516467. Report an issue: GitHub.