eyaltoledano/claude-task-master · error
Prompt must be a non-empty string
Error message
Prompt must be a non-empty string
What it means
validatePrompt() is the base provider's input guard for completion calls. It throws this error when the prompt is falsy or not a string — i.e. null, undefined, a number, or an empty string was passed where a prompt is required.
Source
Thrown at packages/tm-core/src/modules/ai/interfaces/ai-provider.interface.ts:416
stream: false,
topP: 1.0,
frequencyPenalty: 0.0,
presencePenalty: 0.0,
timeout: 30000,
retries: 3,
...this.config.defaultOptions,
...userOptions
};
}
/**
* Validate prompt input
* @param prompt - Prompt to validate
* @throws Error if prompt is invalid
*/
protected validatePrompt(prompt: string): void {
if (!prompt || typeof prompt !== 'string') {
throw new Error('Prompt must be a non-empty string');
}
if (prompt.trim().length === 0) {
throw new Error('Prompt cannot be empty or only whitespace');
}
}
}
View on GitHub (pinned to c0c98d367c)
Solutions
- Ensure the prompt is a non-empty string before calling generateCompletion(prompt, options)
- Stringify/serialize structured messages yourself before passing (e.g. messages.map(m => m.content).join('\n'))
- Coalesce defaults: const prompt = userPrompt ?? fallbackPrompt
Example fix
// before
await provider.generateCompletion(messages); // array, not string
// after
const prompt = messages.map(m => m.content).join('\n');
await provider.generateCompletion(prompt); Defensive patterns
Strategy: validation
Validate before calling
if (typeof prompt !== 'string' || prompt.length === 0) throw new Error('generateCompletion requires a non-empty string prompt'); Type guard
function isUsablePrompt(p: unknown): p is string {
return typeof p === 'string' && p.length > 0;
} Try / catch
try {
return await provider.generateCompletion(prompt, options);
} catch (err) {
if (err.message === 'Prompt must be a non-empty string') {
throw new Error('Prompt building failed — check upstream variables');
}
throw err;
} Prevention
- Type prompt parameters as string and avoid `as any` on message arrays
- Build prompts in a single helper that asserts non-emptiness
- Never pass structured message arrays directly to string-prompt APIs
When it happens
Trigger: generateCompletion(null as any); generateCompletion(undefined) when a variable failed to populate; passing an options object or message array instead of a string; calling with '' after a failed upstream string interpolation.
Common situations: Template variables left undefined in prompt-building code; API refactors that now pass message arrays to a method expecting a plain string; reading a prompt from config/DB that came back null.
Related errors
- Prompt cannot be empty or only whitespace
- Model "${model}" is not available for provider "${this.getNa
- AUTHENTICATION_ERROR
- VALIDATION_ERROR
- ${this.getName()} provider error: ${errorMessage}
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/4c0f04ab761c1bbf.
Report an issue: GitHub.