{"record":{"id":"15d90f6d174372d5","repo":"eyaltoledano/claude-task-master","slug":"ai-service-did-not-return-a-valid-task-object","errorCode":null,"errorMessage":"AI service did not return a valid task object.","messagePattern":"AI service did not return a valid task object\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/task-manager/add-task.js","lineNumber":461,"sourceCode":"\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'AI service did not return the expected object structure.'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Prefer mainResult if it looks like a valid task object, otherwise try mainResult.object\n\t\t\t\tif (\n\t\t\t\t\taiServiceResponse.mainResult.title &&\n\t\t\t\t\taiServiceResponse.mainResult.description\n\t\t\t\t) {\n\t\t\t\t\ttaskData = aiServiceResponse.mainResult;\n\t\t\t\t} else if (\n\t\t\t\t\taiServiceResponse.mainResult.object &&\n\t\t\t\t\taiServiceResponse.mainResult.object.title &&\n\t\t\t\t\taiServiceResponse.mainResult.object.description\n\t\t\t\t) {\n\t\t\t\t\ttaskData = aiServiceResponse.mainResult.object;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error('AI service did not return a valid task object.');\n\t\t\t\t}\n\n\t\t\t\treport('Successfully generated task data from AI.', 'success');\n\n\t\t\t\t// Success! Show checkmark\n\t\t\t\tif (loadingIndicator) {\n\t\t\t\t\tsucceedLoadingIndicator(\n\t\t\t\t\t\tloadingIndicator,\n\t\t\t\t\t\t'Task generated successfully'\n\t\t\t\t\t);\n\t\t\t\t\tloadingIndicator = null; // Clear it\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Failure! Show X\n\t\t\t\tif (loadingIndicator) {\n\t\t\t\t\tfailLoadingIndicator(loadingIndicator, 'AI generation failed');\n\t\t\t\t\tloadingIndicator = null;\n\t\t\t\t}","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/add-task.js#L443-L479","documentation":"Even when the AI service responds with a mainResult, addTask() requires the unwrapped object (mainResult itself, or mainResult.object) to contain title and description fields, since that object becomes taskData. If neither location yields a valid task object, it throws rather than persisting a broken task.","triggerScenarios":"generateObjectService returns { mainResult } but mainResult lacks title/description (e.g. it's an array, a validation-error stub, or the object is nested under a different key not named 'object').","commonSituations":"Model output that fails zod schema validation and is returned partially; provider returning a different schema after a model change; using a model that ignores the requested JSON schema and returns prose or a wrapped envelope.","solutions":["Retry generation, optionally with a more schema-compliant model, since this is usually malformed model output.","Check the zod task schema in generateObjectService — ensure it requires title and description so invalid output is rejected/retried upstream.","Fall back to manual add-task with explicit title and description arguments."],"exampleFix":"// before\nconst data = await generateObjectService(...); // schema allows optional title\n// after\nconst data = await generateObjectService(...); // schema: z.object({ title: z.string().min(1), description: z.string().min(1) })","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isValidTaskObject(res) {\n  const o = res?.mainResult?.object ?? res?.mainResult;\n  return !!o && typeof o === 'object' && typeof o.title === 'string' && o.title.length > 0 && typeof o.description === 'string' && o.description.length > 0;\n}","tryCatchPattern":"try {\n  await addTask(tasksPath, { prompt });\n} catch (err) {\n  if (err.message.includes('did not return a valid task object')) {\n    // retry once, then fall back to manual entry\n    await addTask(tasksPath, { taskData: { title: manualTitle, description: manualDescription } });\n  } else throw err;\n}","preventionTips":["Use models known to follow JSON schemas for task generation.","Enforce strict zod schemas (title/description required) in the generation service.","Retry generation automatically on schema mismatch before giving up."],"tags":["ai-service","schema-validation","add-task"],"backgroundTag":"schema-validation-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}