eyaltoledano/claude-task-master · error
AI service did not return the expected object structure.
Error message
AI service did not return the expected object structure.
What it means
After calling generateObjectService for AI task generation, addTask() checks that the service returned a response object containing a mainResult. A null response or a missing mainResult means the AI service layer returned something unexpected (or nothing), so the raw result cannot be safely unwrapped.
Source
Thrown at scripts/modules/task-manager/add-task.js:443
const serviceRole = useResearch ? 'research' : 'main';
report('DEBUG: Calling generateObjectService...', 'debug');
aiServiceResponse = await generateObjectService({
// Capture the full response
role: serviceRole,
session: session,
projectRoot: projectRoot,
schema: COMMAND_SCHEMAS['add-task'],
objectName: 'newTaskData',
systemPrompt: systemPrompt,
prompt: userPrompt,
commandName: commandName || 'add-task', // Use passed commandName or default
outputType: outputType || (isMCP ? 'mcp' : 'cli') // Use passed outputType or derive
});
report('DEBUG: generateObjectService returned successfully.', 'debug');
if (!aiServiceResponse || !aiServiceResponse.mainResult) {
throw new Error(
'AI service did not return the expected object structure.'
);
}
// Prefer mainResult if it looks like a valid task object, otherwise try mainResult.object
if (
aiServiceResponse.mainResult.title &&
aiServiceResponse.mainResult.description
) {
taskData = aiServiceResponse.mainResult;
} else if (
aiServiceResponse.mainResult.object &&
aiServiceResponse.mainResult.object.title &&
aiServiceResponse.mainResult.object.description
) {
taskData = aiServiceResponse.mainResult.object;
} else {
throw new Error('AI service did not return a valid task object.');View on GitHub (pinned to c0c98d367c)
Solutions
- Verify the AI provider configuration (API key, model, base URL) and retry, since a failed/empty generation is the most common cause.
- Check that generateObjectService is the expected version and returns { mainResult } — update task-master or fix the custom service wrapper.
- Inspect logs/debug output around the generateObjectService call for provider errors and fall back to manual task creation (title + description).
Example fix
// before (custom wrapper)
const response = await myGenerateObject(...); // returns object directly
return response; // addTask expects response.mainResult
// after
const response = await myGenerateObject(...);
return { mainResult: response, telemetry: [] }; Defensive patterns
Strategy: try-catch
Type guard
function hasMainResult(res) {
return !!res && typeof res === 'object' && 'mainResult' in res && res.mainResult !== null;
} Try / catch
try {
await addTask(tasksPath, { prompt });
} catch (err) {
if (err.message.includes('did not return the expected object structure')) {
logger.error('AI service failed; check provider config/API key, then retry or add manually.');
} else throw err;
} Prevention
- Keep AI provider API keys and model config valid (task-master models).
- Don't wrap generateObjectService with code that changes its { mainResult } contract.
- Keep task-master and its ai-services dependency versions in sync.
When it happens
Trigger: generateObjectService returns undefined/null (internal failure swallowed) or returns an object without mainResult — e.g. an unexpected provider response shape, an error object, or a version of the AI service module that changed its return contract.
Common situations: Misconfigured AI provider (bad API key causing an empty result), provider outage returning malformed JSON that fails schema parsing, or a custom/older ai-services-client whose generateObjectService returns the object directly instead of wrapping it in { mainResult }.
Related errors
- AI service did not return a valid task object.
- Manual task data must include at least a title and descripti
- AI response did not include a valid subtasks array.
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/f489adceea053477.
Report an issue: GitHub.