{"record":{"id":"6e48cec67cfd0237","repo":"vxcontrol/pentagi","slug":"error-executing-template-v-6e48ce","errorCode":null,"errorMessage":"error executing template: %v","messagePattern":"error executing template: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/searchers/tavily.go","lineNumber":272,"sourceCode":"{{$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}\n\n\treturn t.cfg.TavilyAPIKey\n}\n","sourceCodeStart":254,"sourceCodeEnd":289,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/searchers/tavily.go#L254-L289","documentation":"getSummarizePrompt returns 'error executing template: %v' when tmpl.Execute fails while rendering the summarize prompt into a bytes.Buffer. Unlike Parse errors, Execute errors usually come from the data side: a missing key with a strict option, a called method that returns an error, or a writer failure.","triggerScenarios":"tmpl.Execute(&buf, templateContext) errors while building the prompt from the tavilySearchResult — e.g. templateContext map missing a key referenced in the template after a schema change to tavilySearchResult (Query/MaxLength/Results mismatch).","commonSituations":"tavilySearchResult struct fields renamed after a Tavily API update while the template still references old names; template invokes a helper function that panics/returns error; concurrent misuse of the buffer.","solutions":["Read the wrapped %v message to identify the failing template expression.","Align template placeholders with current templateContext keys (\"Query\", \"MaxLength\", \"Results\").","Regenerate/adjust code if the Tavily result struct shape changed.","Add a unit test executing the template with representative tavilySearchResult data."],"exampleFix":"// before: template references removed field\n\"...{{range .Hits}}...\"  // Results renamed to Hits\n// after: template matches templateContext keys\n\"...{{range .Results}}...\"","handlingStrategy":"validation","validationCode":"for _, key := range []string{\"Query\", \"MaxLength\", \"Results\"} {\n    if _, ok := templateContext[key]; !ok {\n        return fmt.Errorf(\"missing template key: %s\", key)\n    }\n}","typeGuard":null,"tryCatchPattern":"prompt, err := getSummarizePrompt(ctx, result)\nif err != nil {\n    log.Warnf(\"template execute failed, using raw results: %v\", err)\n    return rawResultsText(result), nil\n}","preventionTips":["Keep template placeholders in sync with templateContext keys via tests","Execute the template with fixture tavilySearchResult data in CI","Update templates whenever tavilySearchResult fields change"],"tags":["go","template","tavily","execution"],"backgroundTag":"template-execute-error","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}