eyaltoledano/claude-task-master · error · TaskMasterError

VALIDATION_ERROR

VALIDATION_ERROR

Error message

validation.error || 'Invalid input'

What it means

generateCompletion() runs validateInput(prompt, options) before any network call; if validation fails it converts the validation message (or the generic 'Invalid input') into a TaskMasterError with code VALIDATION_ERROR. This aggregates prompt problems (missing/empty/too long) and options problems (bad temperature/maxTokens).

Source

Thrown at packages/tm-core/src/modules/ai/providers/base-provider.ts:100

				ERROR_CODES.AUTHENTICATION_ERROR
			);
		}
		this.apiKey = config.apiKey;
		this.model = config.model || this.getDefaultModel();
	}

	/**
	 * Template method for generating completions
	 * Handles validation, retries, and error handling
	 */
	async generateCompletion(
		prompt: string,
		options?: AIOptions
	): Promise<AIResponse> {
		// Validate input
		const validation = this.validateInput(prompt, options);
		if (!validation.valid) {
			throw new TaskMasterError(
				validation.error || 'Invalid input',
				ERROR_CODES.VALIDATION_ERROR
			);
		}

		// Prepare request
		const prepared = this.prepareRequest(prompt, options);

		// Execute with retry logic
		let lastError: Error | undefined;
		const maxRetries = this.getMaxRetries();

		for (let attempt = 1; attempt <= maxRetries; attempt++) {
			try {
				const startTime = Date.now();
				const result = await this.generateCompletionInternal(
					prepared.prompt,
					prepared.options

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Fix the reported validation.error field on the thrown TaskMasterError (it names the exact problem)
  2. Clamp options: temperature between 0 and 1 (MIN/MAX_TEMPERATURE), maxTokens within the provider's allowed range
  3. Check prompt length and trim it below MAX_PROMPT_LENGTH before calling

Example fix

// before
await provider.generateCompletion(prompt, { temperature: 1.5 });
// after
await provider.generateCompletion(prompt, {
  temperature: Math.min(1, Math.max(0, temperature)),
  maxTokens: Math.max(1, Math.min(MAX_MAX_TOKENS, maxTokens))
});
Defensive patterns

Strategy: validation

Validate before calling

function prevalidate(prompt: string, options?: AIOptions): boolean {
  if (!prompt || !prompt.trim()) return false;
  if (options) {
    if (options.temperature !== undefined && (options.temperature < 0 || options.temperature > 1)) return false;
    if (options.maxTokens !== undefined && options.maxTokens <= 0) return false;
  }
  return true;
}

Try / catch

try {
  return await provider.generateCompletion(prompt, options);
} catch (err) {
  if (err instanceof TaskMasterError && err.code === ERROR_CODES.VALIDATION_ERROR) {
    console.error('Input rejected:', err.message);
    return generateWithDefaults(); // retry with clamped/default options
  }
  throw err;
}

Prevention

When it happens

Trigger: generateCompletion with an empty or oversized prompt (> MAX_PROMPT_LENGTH chars); options.temperature outside [MIN_TEMPERATURE, MAX_TEMPERATURE] (e.g. 1.5); negative or huge maxTokens; any invalid options object shape.

Common situations: Passing a raw model output back as a prompt (accumulating past token limits); temperature tuned outside the provider's allowed 0–1 range; maxTokens set to 0 by a caller computing a budget that came out empty.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/bd626171e0cee77d. Report an issue: GitHub.