{"record":{"id":"36e5388afefe7754","repo":"charmbracelet/crush","slug":"error-creating-prompt-s","errorCode":null,"errorMessage":"error creating prompt: %s","messagePattern":"error creating prompt: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/agentic_fetch_tool.go","lineNumber":147,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\ttempFile.Close()\n\n\t\t\t\t\tfullPrompt = 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)\n\t\t\t\t} else {\n\t\t\t\t\tfullPrompt = fmt.Sprintf(\"%s\\n\\nWeb page URL: %s\\n\\n<webpage_content>\\n%s\\n</webpage_content>\", params.Prompt, params.URL, content)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Search mode: let the sub-agent search and fetch as needed.\n\t\t\t\tfullPrompt = 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)\n\t\t\t}\n\n\t\t\tpromptOpts := []prompt.Option{\n\t\t\t\tprompt.WithWorkingDir(tmpDir),\n\t\t\t}\n\n\t\t\tpromptTemplate, err := prompt.NewPrompt(\"agentic_fetch\", string(agenticFetchPromptTmpl), promptOpts...)\n\t\t\tif err != nil {\n\t\t\t\treturn fantasy.ToolResponse{}, fmt.Errorf(\"error creating prompt: %s\", err)\n\t\t\t}\n\n\t\t\t_, small, err := c.buildAgentModels(ctx, true)\n\t\t\tif err != nil {\n\t\t\t\treturn fantasy.ToolResponse{}, fmt.Errorf(\"error building models: %s\", err)\n\t\t\t}\n\n\t\t\tsystemPrompt, err := promptTemplate.Build(ctx, small.Model.Provider(), small.Model.Model(), c.cfg)\n\t\t\tif err != nil {\n\t\t\t\treturn fantasy.ToolResponse{}, fmt.Errorf(\"error building system prompt: %s\", err)\n\t\t\t}\n\n\t\t\tsmallProviderCfg, ok := c.cfg.Config().Providers.Get(small.ModelCfg.Provider)\n\t\t\tif !ok {\n\t\t\t\treturn fantasy.ToolResponse{}, errors.New(\"small model provider not configured\")\n\t\t\t}\n\n\t\t\twebFetchTool := tools.NewWebFetchTool(tmpDir, client)","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/agent/agentic_fetch_tool.go#L129-L165","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\npromptTemplate, err := prompt.NewPrompt(\"agentic_fetch\", string(agenticFetchPromptTmpl), promptOpts...)\nif err != nil {\n    return fantasy.ToolResponse{}, fmt.Errorf(\"error creating prompt: %s\", err)\n}\n// after\n// add a test that parses the template at startup so bad syntax fails fast:\nfunc TestAgenticFetchPromptParses(t *testing.T) {\n    _, err := prompt.NewPrompt(\"agentic_fetch\", string(agenticFetchPromptTmpl), prompt.WithWorkingDir(t.TempDir()))\n    require.NoError(t, err)\n}","handlingStrategy":"validation","validationCode":"// compile-time guard: parse the template in an init/test\n_, err := prompt.NewPrompt(\"agentic_fetch\", string(agenticFetchPromptTmpl), prompt.WithWorkingDir(os.TempDir()))\nif err != nil {\n    panic(fmt.Sprintf(\"agentic_fetch template invalid: %v\", err))\n}","typeGuard":null,"tryCatchPattern":"resp, err := tool.Execute(ctx, params)\nif err != nil && strings.HasPrefix(err.Error(), \"error creating prompt\") {\n    return reportTemplateBug(err) // developer defect; do not retry\n}","preventionTips":["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"],"tags":["template","prompt","tool"],"backgroundTag":"prompt-template-invalid","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}