eyaltoledano/claude-task-master · error
Prompt cannot be empty or only whitespace
Error message
Prompt cannot be empty or only whitespace
What it means
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.
Source
Thrown at packages/tm-core/src/modules/ai/interfaces/ai-provider.interface.ts:420
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
- 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
Example fix
// before
const prompt = `Summarize: ${context}`; // context was ''
await provider.generateCompletion(prompt);
// after
const prompt = `Summarize: ${context}`;
if (!prompt.trim()) throw new Error('Cannot generate: empty prompt');
await provider.generateCompletion(prompt); Defensive patterns
Strategy: validation
Validate before calling
const trimmed = typeof prompt === 'string' ? prompt.trim() : '';
if (!trimmed) throw new Error('Prompt is empty after trimming — check template variables'); Type guard
function hasContent(p: unknown): p is string {
return typeof p === 'string' && p.trim().length > 0;
} Try / catch
try {
return await provider.generateCompletion(prompt);
} catch (err) {
if (err.message.includes('empty or only whitespace')) {
console.error('Prompt was:', JSON.stringify(prompt));
throw new Error('Refusing to send empty prompt');
}
throw err;
} Prevention
- 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
When it happens
Trigger: generateCompletion(' '); generateCompletion('\n\t') from template strings whose interpolated variables were empty; prompts built by joining empty fragments.
Common situations: 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.
Related errors
- Prompt must be a non-empty string
- 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/b53dbb3baa2e0bb9.
Report an issue: GitHub.