{"record":{"id":"1b3f1428ac3fd124","repo":"vxcontrol/pentagi","slug":"error-creating-template-v-1b3f14","errorCode":null,"errorMessage":"error creating template: %v","messagePattern":"error creating template: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/searchers/perplexity.go","lineNumber":342,"sourceCode":"\t\t\"inc\": func(i int) int {\n\t\t\treturn i + 1\n\t\t},\n\t}\n\n\ttemplateContext := map[string]any{\n\t\t\"Query\":        query,\n\t\t\"MaxLength\":    maxRawContentLength,\n\t\t\"Content\":      content,\n\t\t\"HasCitations\": citations != nil && len(*citations) > 0,\n\t}\n\n\tif citations != nil && len(*citations) > 0 {\n\t\ttemplateContext[\"Citations\"] = *citations\n\t}\n\n\ttmpl, err := template.New(\"summarize\").Funcs(funcMap).Parse(templateText)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error creating template: %v\", err)\n\t}\n\n\tvar buf bytes.Buffer\n\tif err := tmpl.Execute(&buf, templateContext); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error executing template: %v\", err)\n\t}\n\n\treturn buf.String(), nil\n}\n\n// isAvailable checks the availability of the API\nfunc (p *perplexity) IsAvailable() bool {\n\treturn p.apiKey() != \"\"\n}\n\nfunc (p *perplexity) apiKey() string {\n\tif p.cfg == nil {\n\t\treturn \"\"","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/searchers/perplexity.go#L324-L360","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n{{range $index, $citation := .Citations}}{{$index | inc}}. {{$citation}}\n{{end}}</citations>\n// after (missing {{end}} restored)\n{{range $index, $citation := .Citations}}{{$index | inc}}. {{$citation}}\n{{end}}\n</citations>\n{{end}}","handlingStrategy":"validation","validationCode":"// parse-time check in a unit test\nfunc TestSummarizeTemplateParses(t *testing.T) {\n    funcMap := template.FuncMap{\"inc\": func(i int) int { return i + 1 }}\n    if _, err := template.New(\"summarize\").Funcs(funcMap).Parse(templateText); err != nil {\n        t.Fatalf(\"summarize template broken: %v\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["go-templates","text-template","perplexity","summarization"],"backgroundTag":"template-parse-error","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}