vxcontrol/pentagi · error

error creating template: %v

Error message

error creating template: %v

What it means

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).

Source

Thrown at backend/pkg/tools/searchers/tavily.go:267

</instructions>

{{range $index, $result := .Results}}
{{if $result.RawContent}}
<raw_content id="{{$index}}" title="{{$result.Title}}" url="{{$result.URL}}">
{{$result.RawContent}}
</raw_content>
{{end}}
{{end}}`

	templateContext := map[string]any{
		"Query":     query,
		"MaxLength": maxRawContentLength,
		"Results":   result.Results,
	}

	tmpl, err := template.New("summarize").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
}

func (t *tavily) IsAvailable() bool {
	return t.apiKey() != ""
}

func (t *tavily) apiKey() string {
	if t.cfg == nil {
		return ""
	}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Read the wrapped %v message — it names the exact line/column of the template syntax error.
  2. Inspect templateText in tavily.go and fix the malformed {{ }} expression.
  3. Test the template in isolation with template.New("summarize").Parse in a unit test.
  4. If interpolating data into templateText, switch to passing data via templateContext instead.

Example fix

// before: interpolating values into the template string
templateText := fmt.Sprintf("Summarize {{.Query}} ... {{ badFunc }}, max %d", maxLen)
// after: keep template static, pass data via context
templateText := "Summarize {{.Query}} ... max {{.MaxLength}}"
templateContext := map[string]any{"Query": query, "MaxLength": maxRawContentLength}
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := template.New("summarize").Parse(templateText); err != nil {
    panic(fmt.Sprintf("invalid summarize template: %v", err))
}

Try / catch

prompt, err := getSummarizePrompt(ctx, result)
if err != nil {
    return "", fmt.Errorf("summarize prompt build failed: %w", err)
}

Prevention

When it happens

Trigger: templateText contains invalid template syntax (unbalanced {{ }}, bad pipeline, unknown function) so Parse fails inside getSummarizePrompt, called from buildTavilyResult.

Common situations: 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.

Related errors


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