siyuan-note/siyuan · error

template output exceeds

Error message

template output exceeds %d bytes

What it means

When a template uses createDocTree (collector.enabled) and the rendered output buffer exceeds maxTemplateDocTreeOutputSize, rendering is aborted with this error to bound memory/output of doc-tree generating templates. It only fires when the collector actually produced doc-tree nodes.

Solutions

  1. Narrow the template's query (add LIMIT / filters) so createDocTree produces fewer nodes.
  2. Split the generation into multiple smaller template runs.
  3. If the limit is genuinely too small for your workload, increase maxTemplateDocTreeOutputSize in the kernel and rebuild.

Example fix

// before (template body)
{{ range .ltsNodes }}{{ createDocTree . "parent-id" }}{{ end }}
// after
{{ range first 100 .ltsNodes }}{{ createDocTree . "parent-id" }}{{ end }}
Defensive patterns

Strategy: try-catch

Validate before calling

// estimate output size before rendering by counting collector input
if len(queryResults) > 1000 { warn("createDocTree output may exceed limit") }

Try / catch

if err != nil && strings.HasPrefix(err.Error(), "template output exceeds") {
    return shrinkQueryAndRetry(templateID)
}

Prevention

When it happens

Trigger: renderTemplateSource after Execute: len(collector.nodes) > 0 and buf.Len() > maxTemplateDocTreeOutputSize — i.e. a createDocTree template whose expanded output is huge (e.g. createDocTree over a query returning thousands of blocks).

Common situations: A template that queries a very large notebook and creates a document tree per result; recursive/looping query expansion; running the template against test data much larger than when it was written.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template.go:914

	tpl, err := goTpl.Funcs(tplFuncMap).Parse(gulu.Str.FromBytes(md))
	if err != nil {
		err = fmt.Errorf(Conf.Language(44), err.Error())
		return
	}
	if collector.enabled && templateUsesFunction(tpl, "createDocTree") {
		if err = validateTemplateCallGraph(tpl, tpl.Name()); nil != err {
			return
		}
	}

	buf := &bytes.Buffer{}
	buf.Grow(4096)
	if err = tpl.Execute(buf, dataModel); err != nil {
		err = fmt.Errorf(Conf.Language(44), err.Error())
		return
	}
	if 0 < len(collector.nodes) && maxTemplateDocTreeOutputSize < buf.Len() {
		err = fmt.Errorf("template output exceeds %d bytes", maxTemplateDocTreeOutputSize)
		return
	}
	collector.totalOutput = buf.Len()
	md = buf.Bytes()
	tree, err = parseTemplateKTree(md)
	if err != nil {
		logging.LogErrorf("parse template [%s] failed: %s", p, err)
		return
	}
	tree.Box = sourceTree.Box
	if 0 < len(collector.nodes) {
		if err = collector.validateLocations(); nil != err {
			return
		}
		if templateTreeContainsAttributeView(tree) {
			err = errors.New("database blocks are not supported by createDocTree templates")
			return
		}

View on GitHub (pinned to 9f775e8a12)