charmbracelet/crush · error
error creating prompt: %s
Error message
error creating prompt: %s
What it means
In the agentic_fetch tool's Execute, prompt.NewPrompt('agentic_fetch', agenticFetchPromptTmpl, promptOpts...) fails to compile/validate the embedded prompt template, and the tool returns 'error creating prompt: %s'. This is a programming/template-authoring defect, not a runtime user error.
Source
Thrown at internal/agent/agentic_fetch_tool.go:147
}
tempFile.Close()
fullPrompt = fmt.Sprintf("%s\n\nThe web page from %s has been saved to: %s\n\nUse the view and grep tools to analyze this file and extract the requested information.", params.Prompt, params.URL, tempFilePath)
} else {
fullPrompt = fmt.Sprintf("%s\n\nWeb page URL: %s\n\n<webpage_content>\n%s\n</webpage_content>", params.Prompt, params.URL, content)
}
} else {
// Search mode: let the sub-agent search and fetch as needed.
fullPrompt = fmt.Sprintf("%s\n\nUse the web_search tool to find relevant information. Break down the question into smaller, focused searches if needed. After searching, use web_fetch to get detailed content from the most relevant results.", params.Prompt)
}
promptOpts := []prompt.Option{
prompt.WithWorkingDir(tmpDir),
}
promptTemplate, err := prompt.NewPrompt("agentic_fetch", string(agenticFetchPromptTmpl), promptOpts...)
if err != nil {
return fantasy.ToolResponse{}, fmt.Errorf("error creating prompt: %s", err)
}
_, small, err := c.buildAgentModels(ctx, true)
if err != nil {
return fantasy.ToolResponse{}, fmt.Errorf("error building models: %s", err)
}
systemPrompt, err := promptTemplate.Build(ctx, small.Model.Provider(), small.Model.Model(), c.cfg)
if err != nil {
return fantasy.ToolResponse{}, fmt.Errorf("error building system prompt: %s", err)
}
smallProviderCfg, ok := c.cfg.Config().Providers.Get(small.ModelCfg.Provider)
if !ok {
return fantasy.ToolResponse{}, errors.New("small model provider not configured")
}
webFetchTool := tools.NewWebFetchTool(tmpDir, client)View on GitHub (pinned to 7944b8e522)
Solutions
- Validate the agenticFetchPromptTmpl template syntax (parse it in a unit test) and fix the syntax error
- Rebuild/reinstall the binary if the template is fine but the binary is stale
- Confirm the promptOpts (working dir) point to a valid directory
Example fix
// before
promptTemplate, err := prompt.NewPrompt("agentic_fetch", string(agenticFetchPromptTmpl), promptOpts...)
if err != nil {
return fantasy.ToolResponse{}, fmt.Errorf("error creating prompt: %s", err)
}
// after
// add a test that parses the template at startup so bad syntax fails fast:
func TestAgenticFetchPromptParses(t *testing.T) {
_, err := prompt.NewPrompt("agentic_fetch", string(agenticFetchPromptTmpl), prompt.WithWorkingDir(t.TempDir()))
require.NoError(t, err)
} Defensive patterns
Strategy: validation
Validate before calling
// compile-time guard: parse the template in an init/test
_, err := prompt.NewPrompt("agentic_fetch", string(agenticFetchPromptTmpl), prompt.WithWorkingDir(os.TempDir()))
if err != nil {
panic(fmt.Sprintf("agentic_fetch template invalid: %v", err))
} Try / catch
resp, err := tool.Execute(ctx, params)
if err != nil && strings.HasPrefix(err.Error(), "error creating prompt") {
return reportTemplateBug(err) // developer defect; do not retry
} Prevention
- Add a unit test that parses every prompt template at build time
- Never interpolate user input into the template source itself
- Re-run template tests after any edit to agenticFetchPromptTmpl
When it happens
Trigger: The agenticFetchPromptTmpl text contains invalid template syntax or prompt.NewPrompt rejects the options (e.g. bad working dir) at Execute time when the tool lazily builds its prompt in tmpDir.
Common situations: A developer edited the agentic fetch prompt template and introduced invalid Go template syntax; shipped binary with a malformed embedded template; unusual tmpDir passed via prompt.WithWorkingDir.
Related errors
- parsing template: %w
- executing template: %w
- failed to create parent directories: %w
- session ID is required for creating a new file
- failed to write file: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/36e5388afefe7754.
Report an issue: GitHub.