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
- Fix the template syntax in templateText — check that every {{if}}/{{range}} has a matching {{end}} and all functions used are in funcMap
- Verify the 'inc' function is still registered in template.FuncMap since the citations range uses it
- Test the template in isolation with template.New("summarize").Funcs(funcMap).Parse on a scratch main to get the exact parse error position
- Revert recent edits to the templateText constant if the error appeared after a prompt change
- 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
- Add a unit test parsing every Go template constant so syntax breakage fails CI
- Keep the 'inc' funcMap entry in sync with template usage
- Balance-check {{if}}/{{range}}/{{end}} after any prompt edit
- Treat template text as code: review prompt-engineering changes with the same rigor as Go code
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
- error executing template: %v
- summarization failed: %w
- failed to get active task input: %w
- failed to get active subtask description: %w
- failed to summarize summary: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/1b3f1428ac3fd124.
Report an issue: GitHub.