vxcontrol/pentagi · error

error executing template: %v

Error message

error executing template: %v

What it means

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.

Source

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

{{$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 ""
	}

	return t.cfg.TavilyAPIKey
}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Read the wrapped %v message to identify the failing template expression.
  2. Align template placeholders with current templateContext keys ("Query", "MaxLength", "Results").
  3. Regenerate/adjust code if the Tavily result struct shape changed.
  4. Add a unit test executing the template with representative tavilySearchResult data.

Example fix

// before: template references removed field
"...{{range .Hits}}..."  // Results renamed to Hits
// after: template matches templateContext keys
"...{{range .Results}}..."
Defensive patterns

Strategy: validation

Validate before calling

for _, key := range []string{"Query", "MaxLength", "Results"} {
    if _, ok := templateContext[key]; !ok {
        return fmt.Errorf("missing template key: %s", key)
    }
}

Try / catch

prompt, err := getSummarizePrompt(ctx, result)
if err != nil {
    log.Warnf("template execute failed, using raw results: %v", err)
    return rawResultsText(result), nil
}

Prevention

When it happens

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

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

Related errors


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