eyaltoledano/claude-task-master · warning

GLM returned a bare array for '${params.objectName}' but cou

Error message

GLM returned a bare array for '${params.objectName}' but could not determine wrapper property from schema. Using objectName as fallback.

What it means

The ZhipuAI GLM provider, when using generateObject, sometimes receives a bare JSON array from the model instead of an object wrapped in the schema's wrapper property. The SDK tries to introspect the schema to find the property name that should hold the array; when introspection fails it logs this warning and wraps the array under params.objectName as a fallback. The result is still returned but the wrapping key is guessed.

Source

Thrown at src/ai-providers/zai.js:108

		const result = await super.generateObject(params);

		// If result.object is an array, wrap it based on schema introspection
		if (Array.isArray(result.object)) {
			// Try to find the array property from the schema
			const wrapperKey = this.findArrayPropertyInSchema(params.schema);

			if (wrapperKey) {
				return {
					...result,
					object: {
						[wrapperKey]: result.object
					}
				};
			}

			// Fallback: if we can't introspect the schema, use the object name
			// This handles edge cases where schema introspection might fail
			console.warn(
				`GLM returned a bare array for '${params.objectName}' but could not determine wrapper property from schema. Using objectName as fallback.`
			);

			return {
				...result,
				object: {
					[params.objectName]: result.object
				}
			};
		}

		return result;
	}
}

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Use a standard Zod object schema with an explicitly named array property (e.g. z.object({ items: z.array(ItemSchema) })) so introspection finds the wrapper.
  2. Read the result via the objectName key, since the fallback wraps the array there; adjust downstream code accordingly.
  3. Strengthen the prompt to request a JSON object with the exact key instead of a top-level array.
  4. Check the schema before the call: if it is not a simple object-with-array shape, restructure it.

Example fix

// before
const schema = z.array(ItemSchema);
// after
const schema = z.object({ items: z.array(ItemSchema) });
Defensive patterns

Strategy: fallback

Validate before calling

const { z } = require('zod');
function isWrapperObjectSchema(schema) {
  return schema instanceof z.ZodObject &&
    Object.values(schema.shape).some(s => s instanceof z.ZodArray);
}
// ensure isWrapperObjectSchema(schema) before calling generateObject

Type guard

function hasWrappedArray(result, key) {
  return result && result.object && typeof result.object === 'object' &&
    Array.isArray(result.object[key]);
}

Try / catch

try {
  const { object } = await generateObject({ model, schema, prompt });
  const items = object.items ?? object; // handle fallback wrapping under objectName
} catch (err) {
  console.error('generateObject failed:', err);
}

Prevention

When it happens

Trigger: Calling generateObject via the ZAI provider where GLM returns a top-level JSON array and the supplied Zod/JSON schema cannot be introspected to find the wrapper property name (unusual schema shapes, non-standard wrappers).

Common situations: Asking the model to return a list of items while using a schema whose array property cannot be inferred; schemas built dynamically; older GLM model versions prone to emitting bare arrays for array-shaped requests.

Related errors


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