siyuan-note/siyuan · error
JSON depth exceeds %d
Error message
JSON depth exceeds %d
What it means
Thrown by validateJSONComplexity (via the recursive walk) when the depth of a JSON value exceeds the supplied maxDepth. For tool schemas the limit is maxToolSchemaDepth=64; for input/output values it is maxToolValueDepth=128. Depth is incremented for each nested object property or array element, so this guards against stack overflow and exponential traversal.
Source
Thrown at kernel/mcp/tools/validation.go:195
result <- err
}()
select {
case err := <-result:
return err
case <-ctx.Done():
return ctx.Err()
case <-timer.C:
return fmt.Errorf("validation exceeded %s", toolValidationTime)
}
}
func validateJSONComplexity(value any, maxDepth, maxNodes int) error {
nodes := 0
var walk func(any, int) error
walk = func(current any, depth int) error {
if depth > maxDepth {
return fmt.Errorf("JSON depth exceeds %d", maxDepth)
}
nodes++
if nodes > maxNodes {
return fmt.Errorf("JSON node count exceeds %d", maxNodes)
}
switch typed := current.(type) {
case map[string]any:
for _, child := range typed {
if err := walk(child, depth+1); err != nil {
return err
}
}
case []any:
for _, child := range typed {
if err := walk(child, depth+1); err != nil {
return err
}
}View on GitHub (pinned to 251596fc0d)
Solutions
- Flatten deeply nested data before submission (e.g., represent a tree as a flat list of {id,parentId} records).
- Cap nesting depth at the source: enforce a maximum depth when constructing the value.
- If the data is legitimately deep but within reason, confirm it stays under 64 (schema) or 128 (value) and that you are not accidentally double-nesting (wrapping in an extra array/object layer).
Example fix
// before: arbitrarily deep nested tree
deep := buildTree(200) // depth 200 > 128
// after: flatten
flat := flatten(deep) // []map[string]any{"id":..,"parentID":..} Defensive patterns
Strategy: validation
Validate before calling
func depth(v any, d int) int {
max := d
switch t := v.(type) {
case map[string]any:
for _, c := range t { if m := depth(c, d+1); m > max { max = m } }
case []any:
for _, c := range t { if m := depth(c, d+1); m > max { max = m } }
}
return max
}
if depth(value, 0) > 128 { return errors.New("value too deep") } Prevention
- Flatten tree-shaped data to {id,parentId} lists before submission.
- Enforce a maximum nesting depth at the data source.
- Reject or paginate inputs that exceed a sane depth before calling the validator.
When it happens
Trigger: Submitting a schema or a value whose nesting depth exceeds 64 (schema) or 128 (value). validateJSONComplexity is called in resolveToolSchema (schemas) and in prepareValidationValue (values).
Common situations: A recursively defined data structure serialized to arbitrary depth; a tool argument that accepts a deeply nested tree (e.g., a parsed AST or a thread of replies) without a depth cap; a generated schema that nests $defs deeply.
Related errors
- JSON node count exceeds %d
- parse [h] failed: %s
- filter nesting depth exceeds the maximum allowed
- invalid marketplace package manifest
- invalid JSON: %s
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/f35dcd9e242a4f43.
Report an issue: GitHub.