siyuan-note/siyuan · error

invalid input schema: %w

Error message

invalid input schema: %w

What it means

CompileToolValidator resolves the tool's InputSchema via resolveToolSchema and wraps any failure with "invalid input schema: %w". The input schema must be a valid JSON Schema document, marshalable, within size/depth/node limits, and its root type must be "object". This error means the tool's declared input schema is malformed or violates one of those constraints.

Source

Thrown at kernel/mcp/tools/validation.go:53

	maxToolValueNodes         = 256 << 10
	toolValidationTime        = 2 * time.Second
	toolValidationConcurrency = 4
)

type ToolValidator struct {
	input           *jsonschema.Resolved
	output          *jsonschema.Resolved
	validationSlots chan struct{}
}

func CompileToolValidator(tool *Tool) (*ToolValidator, error) {
	if tool == nil {
		return nil, fmt.Errorf("tool is nil")
	}

	input, err := resolveToolSchema(tool.InputSchema, true)
	if err != nil {
		return nil, fmt.Errorf("invalid input schema: %w", err)
	}

	var output *jsonschema.Resolved
	if tool.OutputSchema != nil {
		if output, err = resolveToolSchema(*tool.OutputSchema, false); err != nil {
			return nil, fmt.Errorf("invalid output schema: %w", err)
		}
	}
	return &ToolValidator{
		input:           input,
		output:          output,
		validationSlots: make(chan struct{}, toolValidationConcurrency),
	}, nil
}

func resolveToolSchema(schema ToolSchema, requireObject bool) (*jsonschema.Resolved, error) {
	if schema.Raw != nil {
		if err := validateJSONComplexity(schema.Raw, maxToolSchemaDepth, maxToolSchemaNodes); err != nil {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Read the wrapped cause (%w) for the concrete schema problem.
  2. Ensure the root of InputSchema is {"type":"object"}; wrap array/string payloads in an object property.
  3. Validate the schema with a JSON Schema validator before registration.
  4. Reduce schema size/depth: drop unused properties, flatten deep allOf/oneOf nesting.

Example fix

// before
InputSchema: map[string]any{"type": "array", "items": ...}
// after
InputSchema: map[string]any{"type": "object", "properties": map[string]any{"items": map[string]any{"type": "array", ...}}}
Defensive patterns

Strategy: validation

Validate before calling

func inputSchemaOK(s map[string]any) error {
    if s["type"] != "object" {
        return errors.New("input schema root type must be object")
    }
    data, _ := json.Marshal(s)
    if len(data) > 1<<20 {
        return errors.New("input schema exceeds 1MiB")
    }
    return nil
}

Type guard

obj, ok := schema["type"].(string); ok && obj == "object"

Try / catch

tool, err := tools.SetTool(name, def)
if err != nil {
    var schemaErr error
    if errors.Unwrap(err) != nil {
        schemaErr = errors.Unwrap(err)
    }
    return fmt.Errorf("register tool %q: %w", name, err) // log wrapped cause
}

Prevention

When it happens

Trigger: Registering a Tool whose InputSchema is invalid JSON Schema, exceeds maxToolSchemaBytes (1 MiB), is too deeply nested, has too many nodes, or whose root "type" is not "object" (e.g. "array" or "string").

Common situations: Hand-written schemas with typos in keywords; schemas generated from another spec with a non-object root; oversized auto-generated schemas; schema built for an array-typed input.

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/9cb98b9e0bba64ec. Report an issue: GitHub.