{"record":{"id":"b53dbb3baa2e0bb9","repo":"eyaltoledano/claude-task-master","slug":"prompt-cannot-be-empty-or-only-whitespace","errorCode":null,"errorMessage":"Prompt cannot be empty or only whitespace","messagePattern":"Prompt cannot be empty or only whitespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/ai/interfaces/ai-provider.interface.ts","lineNumber":420,"sourceCode":"\t\t\ttimeout: 30000,\n\t\t\tretries: 3,\n\t\t\t...this.config.defaultOptions,\n\t\t\t...userOptions\n\t\t};\n\t}\n\n\t/**\n\t * Validate prompt input\n\t * @param prompt - Prompt to validate\n\t * @throws Error if prompt is invalid\n\t */\n\tprotected validatePrompt(prompt: string): void {\n\t\tif (!prompt || typeof prompt !== 'string') {\n\t\t\tthrow new Error('Prompt must be a non-empty string');\n\t\t}\n\n\t\tif (prompt.trim().length === 0) {\n\t\t\tthrow new Error('Prompt cannot be empty or only whitespace');\n\t\t}\n\t}\n}\n","sourceCodeStart":402,"sourceCodeEnd":424,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/ai/interfaces/ai-provider.interface.ts#L402-L424","documentation":"validatePrompt() rejects prompts that are strings but contain only whitespace (or nothing after trim), because sending an all-whitespace prompt to an LLM is always a caller bug. It fires after the non-string/null check in the same method.","triggerScenarios":"generateCompletion('   '); generateCompletion('\\n\\t') from template strings whose interpolated variables were empty; prompts built by joining empty fragments.","commonSituations":"Prompt templates where every ${var} expanded to empty (missing context, failed retrieval); copy-paste artifacts that are just spaces; trimming logic upstream that emptied the prompt before the call.","solutions":["Check prompt.trim().length > 0 before calling the provider","Fix the template/interpolation that produced a whitespace-only prompt","Provide a fallback or reject the request upstream when the assembled prompt is empty"],"exampleFix":"// before\nconst prompt = `Summarize: ${context}`; // context was ''\nawait provider.generateCompletion(prompt);\n// after\nconst prompt = `Summarize: ${context}`;\nif (!prompt.trim()) throw new Error('Cannot generate: empty prompt');\nawait provider.generateCompletion(prompt);","handlingStrategy":"validation","validationCode":"const trimmed = typeof prompt === 'string' ? prompt.trim() : '';\nif (!trimmed) throw new Error('Prompt is empty after trimming — check template variables');","typeGuard":"function hasContent(p: unknown): p is string {\n  return typeof p === 'string' && p.trim().length > 0;\n}","tryCatchPattern":"try {\n  return await provider.generateCompletion(prompt);\n} catch (err) {\n  if (err.message.includes('empty or only whitespace')) {\n    console.error('Prompt was:', JSON.stringify(prompt));\n    throw new Error('Refusing to send empty prompt');\n  }\n  throw err;\n}","preventionTips":["After building a prompt from templates, assert it is non-empty","Log JSON.stringify(prompt) when debugging template expansion","Fail fast on empty interpolated variables instead of letting '' propagate"],"tags":["ai-provider","input-validation","prompt"],"backgroundTag":"invalid-prompt-input","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}