linshenkx/prompt-optimizer · error · Error
Prompt must be a non-empty string
Error message
Prompt must be a non-empty string
What it means
ParameterAdapter.validatePrompt rejects a prompt argument that is falsy, not a string, or a string containing only whitespace. It runs in the MCP server request handlers, guarding the core prompt input before processing; a second check enforces the 50,000-character maximum.
Source
Thrown at packages/mcp-server/src/adapters/parameter-adapter.ts:13
/**
* 参数验证工具
* 简化的参数验证,移除过度抽象
*/
export class ParameterValidator {
/**
* 验证提示词输入
*/
static validatePrompt(prompt: string): void {
if (!prompt || typeof prompt !== 'string' || prompt.trim().length === 0) {
throw new Error('Prompt must be a non-empty string');
}
if (prompt.length > 50000) {
throw new Error('Prompt must not exceed 50,000 characters');
}
}
/**
* 验证模板输入
*/
static validateTemplate(template?: string): void {
if (template !== undefined && (typeof template !== 'string' || template.trim().length === 0)) {
throw new Error('Template must be a non-empty string');
}
}
/**
* 验证需求描述输入
*/View on GitHub (pinned to 3e677b1d9f)
Solutions
- Ensure the caller always sends a non-empty trimmed string for prompt
- Trim/validate client-side before invoking: if (!prompt?.trim()) fix the caller
- Check the tool's input schema and the client's argument construction for typos in the parameter name
- If undefined is legitimate for your flow, substitute a default prompt string before calling
Example fix
// before
await tool.call({ prompt: userInput }); // userInput may be ''
// after
await tool.call({ prompt: (userInput ?? '').trim() || fallbackPrompt }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof prompt !== 'string' || prompt.trim().length === 0) {
throw new Error('client-side: prompt required');
} Type guard
const isValidPrompt = (p: unknown): p is string => typeof p === 'string' && p.trim().length > 0;
Try / catch
try {
await server.callTool('prompt', { prompt });
} catch (e) {
if ((e as Error).message.includes('Prompt must be a non-empty string')) {
return { error: 'Please provide a prompt' };
}
throw e;
} Prevention
- Validate tool inputs client-side with the tool's schema before sending
- Trim user input and reject empty submissions in the UI
When it happens
Trigger: Calling the MCP tool/prompt endpoint with prompt: '' , prompt: null, prompt: 123 (wrong type), or prompt: ' ' (whitespace only). These typically come from an LLM client constructing tool-call arguments incorrectly.
Common situations: An MCP client (Claude, Cursor, custom integration) omitting the prompt field or sending an empty string; templating bugs producing undefined interpolated into the call; schema drift where the client sends a different parameter name so prompt arrives undefined.
Related errors
- Prompt must not exceed 50,000 characters
- Template must be a non-empty string
- Requirements must be a non-empty string
- Iteration requirement must not be empty.
- ${label} promptText must not be empty.
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/16d1375906aa23a5.
Report an issue: GitHub.