{"record":{"id":"40077fca4018b4fc","repo":"vxcontrol/pentagi","slug":"error-creating-template-v-40077f","errorCode":null,"errorMessage":"error creating template: %v","messagePattern":"error creating template: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/searchers/tavily.go","lineNumber":267,"sourceCode":"</instructions>\n\n{{range $index, $result := .Results}}\n{{if $result.RawContent}}\n<raw_content id=\"{{$index}}\" title=\"{{$result.Title}}\" url=\"{{$result.URL}}\">\n{{$result.RawContent}}\n</raw_content>\n{{end}}\n{{end}}`\n\n\ttemplateContext := map[string]any{\n\t\t\"Query\":     query,\n\t\t\"MaxLength\": maxRawContentLength,\n\t\t\"Results\":   result.Results,\n\t}\n\n\ttmpl, err := template.New(\"summarize\").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\nfunc (t *tavily) IsAvailable() bool {\n\treturn t.apiKey() != \"\"\n}\n\nfunc (t *tavily) apiKey() string {\n\tif t.cfg == nil {\n\t\treturn \"\"\n\t}","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/searchers/tavily.go#L249-L285","documentation":"getSummarizePrompt builds a Go text/template for summarizing Tavily results and returns 'error creating template: %v' when template.New(\"summarize\").Parse(templateText) fails. Parse only fails on template syntax errors, so this indicates the hardcoded template text in the source is malformed (or was edited/overridden incorrectly).","triggerScenarios":"templateText contains invalid template syntax (unbalanced {{ }}, bad pipeline, unknown function) so Parse fails inside getSummarizePrompt, called from buildTavilyResult.","commonSituations":"A developer edited the summarize template and introduced bad Go template syntax; a merge conflict left stray '{{'; a custom fork interpolates values into the template string incorrectly before parsing.","solutions":["Read the wrapped %v message — it names the exact line/column of the template syntax error.","Inspect templateText in tavily.go and fix the malformed {{ }} expression.","Test the template in isolation with template.New(\"summarize\").Parse in a unit test.","If interpolating data into templateText, switch to passing data via templateContext instead."],"exampleFix":"// before: interpolating values into the template string\ntemplateText := fmt.Sprintf(\"Summarize {{.Query}} ... {{ badFunc }}, max %d\", maxLen)\n// after: keep template static, pass data via context\ntemplateText := \"Summarize {{.Query}} ... max {{.MaxLength}}\"\ntemplateContext := map[string]any{\"Query\": query, \"MaxLength\": maxRawContentLength}","handlingStrategy":"try-catch","validationCode":"if _, err := template.New(\"summarize\").Parse(templateText); err != nil {\n    panic(fmt.Sprintf(\"invalid summarize template: %v\", err))\n}","typeGuard":null,"tryCatchPattern":"prompt, err := getSummarizePrompt(ctx, result)\nif err != nil {\n    return \"\", fmt.Errorf(\"summarize prompt build failed: %w\", err)\n}","preventionTips":["Parse the template once at construction time, not per request","Add a unit test that parses every prompt template","Never build template text with fmt.Sprintf interpolation"],"tags":["go","template","tavily","syntax"],"backgroundTag":"template-parse-error","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}