{"record":{"id":"3968e9e96a73e5b4","repo":"eyaltoledano/claude-task-master","slug":"glm-returned-a-bare-array-for-params-objectname","errorCode":null,"errorMessage":"GLM returned a bare array for '${params.objectName}' but could not determine wrapper property from schema. Using objectName as fallback.","messagePattern":"GLM returned a bare array for '(.+?)' but could not determine wrapper property from schema\\. Using objectName as fallback\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/ai-providers/zai.js","lineNumber":108,"sourceCode":"\t\tconst result = await super.generateObject(params);\n\n\t\t// If result.object is an array, wrap it based on schema introspection\n\t\tif (Array.isArray(result.object)) {\n\t\t\t// Try to find the array property from the schema\n\t\t\tconst wrapperKey = this.findArrayPropertyInSchema(params.schema);\n\n\t\t\tif (wrapperKey) {\n\t\t\t\treturn {\n\t\t\t\t\t...result,\n\t\t\t\t\tobject: {\n\t\t\t\t\t\t[wrapperKey]: result.object\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Fallback: if we can't introspect the schema, use the object name\n\t\t\t// This handles edge cases where schema introspection might fail\n\t\t\tconsole.warn(\n\t\t\t\t`GLM returned a bare array for '${params.objectName}' but could not determine wrapper property from schema. Using objectName as fallback.`\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\tobject: {\n\t\t\t\t\t[params.objectName]: result.object\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\treturn result;\n\t}\n}\n","sourceCodeStart":90,"sourceCodeEnd":123,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/src/ai-providers/zai.js#L90-L123","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["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.","Read the result via the objectName key, since the fallback wraps the array there; adjust downstream code accordingly.","Strengthen the prompt to request a JSON object with the exact key instead of a top-level array.","Check the schema before the call: if it is not a simple object-with-array shape, restructure it."],"exampleFix":"// before\nconst schema = z.array(ItemSchema);\n// after\nconst schema = z.object({ items: z.array(ItemSchema) });","handlingStrategy":"fallback","validationCode":"const { z } = require('zod');\nfunction isWrapperObjectSchema(schema) {\n  return schema instanceof z.ZodObject &&\n    Object.values(schema.shape).some(s => s instanceof z.ZodArray);\n}\n// ensure isWrapperObjectSchema(schema) before calling generateObject","typeGuard":"function hasWrappedArray(result, key) {\n  return result && result.object && typeof result.object === 'object' &&\n    Array.isArray(result.object[key]);\n}","tryCatchPattern":"try {\n  const { object } = await generateObject({ model, schema, prompt });\n  const items = object.items ?? object; // handle fallback wrapping under objectName\n} catch (err) {\n  console.error('generateObject failed:', err);\n}","preventionTips":["Always define schemas as z.object({ namedArray: z.array(...) }), never bare z.array().","Name the array property the same as params.objectName so fallback and schema agree.","Log/inspect result.object shape once during development to catch bare-array responses early.","Pin and test against the GLM model version you deploy with."],"tags":["ai-provider","schema","glm","response-shape"],"backgroundTag":"schema-introspection-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}