vxcontrol/pentagi · error

template content is empty

Error message

template content is empty

What it means

ExtractTemplateVariables parses Go text/template content to extract top-level variables. It rejects whitespace-only or empty template content up front because there is nothing to parse. It is a guard against silently returning zero variables for blank input.

Source

Thrown at backend/pkg/templates/validator/validator.go:104

	}

	// Test template rendering with mock data
	mockData := CreateDummyTemplateData()
	if err := testTemplateRendering(prompt, mockData); err != nil {
		return &ValidationError{
			Type:    ErrorTypeRenderingFailed,
			Message: fmt.Sprintf("template rendering failed: %v", err),
			Details: extractRenderingDetails(err),
		}
	}

	return nil
}

// ExtractTemplateVariables parses a template and extracts all top-level variables
func ExtractTemplateVariables(templateContent string) ([]string, error) {
	if strings.TrimSpace(templateContent) == "" {
		return nil, fmt.Errorf("template content is empty")
	}

	// Create function map with all builtin functions as nil values for the parser
	funcMap := template.FuncMap{
		// Builtin comparison and logic functions
		"and": nil, "or": nil, "not": nil,
		"eq": nil, "ne": nil, "lt": nil, "le": nil, "gt": nil, "ge": nil,
		// Builtin utility functions
		"len": nil, "index": nil, "slice": nil, "print": nil, "printf": nil, "println": nil,
		"html": nil, "js": nil, "urlquery": nil, "call": nil,
		// Additional common functions that might be used
		"add": nil, "sub": nil, "mul": nil, "div": nil, "mod": nil,
		"upper": nil, "lower": nil, "title": nil, "trim": nil, "trimSpace": nil,
		"default": nil, "empty": nil, "contains": nil, "hasPrefix": nil, "hasSuffix": nil,
	}

	// Parse template with function map to get AST
	parsed, err := parse.Parse("validation", templateContent, "{{", "}}", funcMap)

View on GitHub (pinned to ea665308ba)

Solutions

  1. Supply non-empty template content before calling ExtractTemplateVariables/ValidatePrompt.
  2. Check where the template is loaded from (env var, DB row, file) — the source is empty or unset.
  3. Add an earlier validation layer (zod on frontend, required field on backend) so blank prompts never reach the validator.

Example fix

// before
vars, err := validator.ExtractTemplateVariables(cfg.SystemPrompt) // cfg.SystemPrompt == ""
// after
if strings.TrimSpace(cfg.SystemPrompt) == "" {
    return fmt.Errorf("system prompt template must be configured")
}
vars, err := validator.ExtractTemplateVariables(cfg.SystemPrompt)
Defensive patterns

Strategy: validation

Validate before calling

func templateNonEmpty(s string) bool { return strings.TrimSpace(s) != "" }
if !templateNonEmpty(cfg.SystemPrompt) { return errors.New("template must be non-empty") }

Type guard

func hasTemplateContent(s string) bool {
    return len(strings.TrimSpace(s)) > 0
}

Try / catch

vars, err := validator.ExtractTemplateVariables(tmpl)
if err != nil && strings.Contains(err.Error(), "template content is empty") {
    // fall back to a default template or surface a config error
}

Prevention

When it happens

Trigger: Calling validator.ExtractTemplateVariables("") or with a string of only spaces/tabs/newlines, directly or indirectly through ValidatePrompt with an empty prompt template.

Common situations: A prompt stored in the DB or config file is blank (misconfigured seed data); an env var supplying the template was never set; a user saved an empty custom prompt in settings.

Related errors


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