eyaltoledano/claude-task-master · error · Error

Schema is required for object generation

Error message

Schema is required for object generation

What it means

BaseAIProvider.generateObject produces a typed structured object and requires a schema describing its shape. The error is thrown when params.schema is missing or falsy after message/param validation, before contacting the provider API.

Source

Thrown at src/ai-providers/base-provider.js:497

			// Return the stream result directly
			// The stream result contains partialObjectStream and other properties
			return result;
		} catch (error) {
			this.handleError('object streaming', error);
		}
	}

	/**
	 * Generates a structured object using the provider's model
	 */
	async generateObject(params) {
		try {
			this.validateParams(params);
			this.validateMessages(params.messages);

			if (!params.schema) {
				throw new Error('Schema is required for object generation');
			}
			if (!params.objectName) {
				throw new Error('Object name is required for object generation');
			}

			log(
				'debug',
				`Generating ${this.name} object ('${params.objectName}') with model: ${params.modelId}`
			);

			const client = await this.getClient(params);

			// Get Sentry telemetry config with function ID and metadata for better tracing
			// Format: provider.model.command.method.objectName
			const commandName = params.commandName || 'unknown';
			const functionId = `${this.name}.${params.modelId}.${commandName}.generateObject.${params.objectName}`;

			// Build telemetry metadata for enhanced filtering/grouping in Sentry

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Supply a valid schema in params.schema (e.g. z.object({...}))
  2. Assert the schema is defined before calling generateObject
  3. Use generateText if structured output is not needed

Example fix

// before
await provider.generateObject({ modelId: 'x', messages, objectName: 'task' });
// after
await provider.generateObject({ modelId: 'x', messages, objectName: 'task', schema: z.object({ title: z.string() }) });
Defensive patterns

Strategy: validation

Validate before calling

function assertGenerateObjectParams(params) {
  if (!params?.schema) throw new Error('generateObject requires params.schema');
  if (!params?.objectName) throw new Error('generateObject requires params.objectName');
}

Type guard

function hasSchema(params) {
  return typeof params === 'object' && params !== null && params.schema != null;
}

Try / catch

try {
  await provider.generateObject(params);
} catch (e) {
  if (e.message === 'Schema is required for object generation') {
    console.error('params.schema missing; pass a Zod schema');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling provider.generateObject({ modelId, messages, objectName }) without the schema field, or schema is undefined/null due to failed initialization.

Common situations: Building params conditionally; copying a generateText example and adding objectName but not schema; schema import resolving to undefined after a refactor.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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