linshenkx/prompt-optimizer · error · Error

Requirements must be a non-empty string

Error message

Requirements must be a non-empty string

What it means

ParameterAdapter.validateRequirements rejects a requirements argument that is falsy, not a string, or whitespace-only. It mirrors validatePrompt but for the requirements (需求描述) input, and is enforced by the MCP server handlers before processing.

Source

Thrown at packages/mcp-server/src/adapters/parameter-adapter.ts:34

      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');
    }
  }

  /**
   * 验证需求描述输入
   */
  static validateRequirements(requirements: string): void {
    if (!requirements || typeof requirements !== 'string' || requirements.trim().length === 0) {
      throw new Error('Requirements must be a non-empty string');
    }
    if (requirements.length > 10000) {
      throw new Error('Requirements must not exceed 10,000 characters');
    }
  }
}

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Always supply a non-empty trimmed requirements string
  2. Validate client-side: if (!requirements?.trim()) prompt the user for input
  3. Check the tool schema to confirm whether requirements is required for the specific endpoint you call

Example fix

// before
await tool.call({ requirements: spec ?? '' });

// after
if (!spec?.trim()) throw new Error('requirements is required');
await tool.call({ requirements: spec.trim() });
Defensive patterns

Strategy: validation

Validate before calling

if (!requirements?.trim()) throw new Error('client-side: requirements required');

Type guard

const isValidRequirements = (r: unknown): r is string =>
  typeof r === 'string' && r.trim().length > 0;

Try / catch

try { await call({ requirements }); } catch (e) { if ((e as Error).message.includes('Requirements must be a non-empty')) return { error: 'requirements missing' }; throw e; }

Prevention

When it happens

Trigger: Calling a tool that requires requirements with requirements: '', null, a non-string value, or only whitespace. Clients that treat requirements as optional will hit this because the validator requires a non-empty string.

Common situations: Tool schema marks requirements required but the client omits it; a form field left blank producing ''; parameter-name drift so requirements arrives undefined.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/17ea344f47ce40d9. Report an issue: GitHub.