vxcontrol/pentagi · error

error creating template: %v

Error message

error creating template: %v

What it means

This error comes from Go's text/template Parse failing while building the summarization prompt template in getSummarizePrompt. Parse errors are static template syntax problems (bad actions, unknown functions, unbalanced braces). Because templateText is a hardcoded constant and funcMap ('inc') is fixed, this should never fire at runtime — it indicates the template source itself was modified incorrectly.

Source

Thrown at backend/pkg/tools/searchers/perplexity.go:342

		"inc": func(i int) int {
			return i + 1
		},
	}

	templateContext := map[string]any{
		"Query":        query,
		"MaxLength":    maxRawContentLength,
		"Content":      content,
		"HasCitations": citations != nil && len(*citations) > 0,
	}

	if citations != nil && len(*citations) > 0 {
		templateContext["Citations"] = *citations
	}

	tmpl, err := template.New("summarize").Funcs(funcMap).Parse(templateText)
	if err != nil {
		return "", fmt.Errorf("error creating template: %v", err)
	}

	var buf bytes.Buffer
	if err := tmpl.Execute(&buf, templateContext); err != nil {
		return "", fmt.Errorf("error executing template: %v", err)
	}

	return buf.String(), nil
}

// isAvailable checks the availability of the API
func (p *perplexity) IsAvailable() bool {
	return p.apiKey() != ""
}

func (p *perplexity) apiKey() string {
	if p.cfg == nil {
		return ""

View on GitHub (pinned to ea665308ba)

Solutions

  1. Fix the template syntax in templateText — check that every {{if}}/{{range}} has a matching {{end}} and all functions used are in funcMap
  2. Verify the 'inc' function is still registered in template.FuncMap since the citations range uses it
  3. Test the template in isolation with template.New("summarize").Funcs(funcMap).Parse on a scratch main to get the exact parse error position
  4. Revert recent edits to the templateText constant if the error appeared after a prompt change
  5. Note that formatResponse silently falls back to truncation when getSummarizePrompt errors, so also check logs to confirm the summarizer path is degraded

Example fix

// before
{{range $index, $citation := .Citations}}{{$index | inc}}. {{$citation}}
{{end}}</citations>
// after (missing {{end}} restored)
{{range $index, $citation := .Citations}}{{$index | inc}}. {{$citation}}
{{end}}
</citations>
{{end}}
Defensive patterns

Strategy: validation

Validate before calling

// parse-time check in a unit test
func TestSummarizeTemplateParses(t *testing.T) {
    funcMap := template.FuncMap{"inc": func(i int) int { return i + 1 }}
    if _, err := template.New("summarize").Funcs(funcMap).Parse(templateText); err != nil {
        t.Fatalf("summarize template broken: %v", err)
    }
}

Prevention

When it happens

Trigger: A developer edits the templateText constant and introduces invalid template syntax: misspelled action delimiters ({{ ! {{), references to a function absent from funcMap (e.g. a new pipeline function not registered), or unbalanced {{if}}/{{end}} blocks.

Common situations: Patching the summarize prompt for prompt-engineering changes and breaking {{range $index, $citation := .Citations}} or the {{if .HasCitations}} block; renaming a template variable without updating all references; removing the 'inc' FuncMap entry while the template still calls it.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/1b3f1428ac3fd124. Report an issue: GitHub.