siyuan-note/siyuan · error

value exceeds bytes

Error message

value exceeds %d bytes

What it means

prepareValidationValue enforces a size budget on values being validated (tool arguments or structured output): the JSON serialization must not exceed maxToolValueBytes (8 MiB). Oversized values are rejected up front to keep schema validation cheap and predictable.

Solutions

  1. Pass file paths or asset references instead of inlining large contents in tool arguments.
  2. Truncate, paginate, or summarize large result sets in structured output.
  3. Check the JSON size of the payload before the call (len of json.Marshal) and split it.
  4. Move bulk data to a dedicated upload/download mechanism outside the tool arguments.

Example fix

// before
args := map[string]any{"content": string(hugeFileBytes)} // > 8 MiB
// after
args := map[string]any{"path": "assets/data.json"} // reference the file by workspace-relative path
Defensive patterns

Strategy: validation

Validate before calling

const size = new Blob([JSON.stringify(arguments)]).size;
if (size > 8 * 1024 * 1024) throw new Error("tool arguments exceed 8 MiB limit");

Prevention

When it happens

Trigger: ValidateInputContext receives arguments whose JSON encoding exceeds 8 MiB, or ValidateOutputContext receives StructuredContent whose encoding exceeds 8 MiB — e.g. embedding large file contents, base64 blobs, or dumping whole documents into a tool call.

Common situations: Agents passing whole-file contents through tool arguments instead of paths; handlers echoing large query results in structured output; accidental inclusion of binary data as base64 strings.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/300bf8384fcbd405. Report an issue: GitHub.

Appendix: source

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

		return fmt.Errorf("structured content is required when an output schema is defined")
	}
	value, err := prepareValidationValue(result.StructuredContent)
	if err != nil {
		return fmt.Errorf("prepare structured content: %w", err)
	}
	return validateResolved(ctx, validator.validationSlots, validator.output, value)
}

func prepareValidationValue(value any) (any, error) {
	if err := validateJSONComplexity(value, maxToolValueDepth, maxToolValueNodes); err != nil {
		return nil, err
	}
	data, err := json.Marshal(value)
	if err != nil {
		return nil, err
	}
	if len(data) > maxToolValueBytes {
		return nil, fmt.Errorf("value exceeds %d bytes", maxToolValueBytes)
	}
	var canonical any
	if err = json.Unmarshal(data, &canonical); err != nil {
		return nil, err
	}
	if err = validateJSONComplexity(canonical, maxToolValueDepth, maxToolValueNodes); err != nil {
		return nil, err
	}
	return canonical, nil
}

func validateResolved(ctx context.Context, validationSlots chan struct{}, schema *jsonschema.Resolved, value any) error {
	if ctx == nil {
		ctx = context.Background()
	}
	timer := time.NewTimer(toolValidationTime)
	defer timer.Stop()

View on GitHub (pinned to 9f775e8a12)