bug: unable to extract JSON content when expanding task
Description
When running the task-master expand command, it seems to be breaking when getting some special characters.
Is there a way to debug this to understand what is the expand response?
Steps to Reproduce
- For this task:
{
"taskId": 3,
"taskTitle": "Create HTTP Client with Authentication",
"complexityScore": 8,
"recommendedSubtasks": 4,
"expansionPrompt": "Break down the HTTP client implementation into subtasks covering: 1) Core fetch wrapper with authentication, 2) Advanced features including timeout, retries, and error handling, 3) Caching implementation, and 4) Comprehensive testing strategy. For each subtask, include detailed implementation code, TypeScript interfaces, and test scenarios.",
"reasoning": "This task involves complex asynchronous operations, error handling, retry logic, and caching. It requires deep understanding of JavaScript promises, fetch API, and HTTP protocols. The implementation needs to be robust and handle various edge cases while maintaining type safety."
},
- Run command:
task-master expand --id=3 --num=4 --prompt="Break down the HTTP client implementation into subtasks covering: 1) Core fetch wrapper with authentication, 2) Advanced features including timeout, retries, and error handling, 3) Caching implementation, and 4) Comprehensive testing strategy. For each subtask, include detailed implementation code, TypeScript interfaces, and test scenarios."
- Output:
Expanding task 3...
[INFO] Reading tasks from <PROJECT_PATH>/tasks/tasks.json
[INFO] Expanding task 3: Create HTTP Client with Authentication
[INFO] Found complexity analysis for task 3: Score 8
[INFO] Using explicitly provided subtask count: 4
[INFO] Using expansion prompt from complexity report and simplified system prompt for task 3.
⠋ Generating 4 subtasks...[INFO] Using AI service with role: main
[INFO] generateTextService called {"role":"main","projectRoot":"<PROJECT_PATH>"}
[INFO] New AI service call with role: main
[INFO] Attempt 1/3 calling generateAnthropicText (Provider: anthropic, Model: claude-3-7-sonnet-20250219, Role: main)
⠴ Generating 4 subtasks...[INFO] generateAnthropicText succeeded for role main (Provider: anthropic) on attempt 1
[INFO] generateTextService succeeded using role: main
[INFO] Successfully received text response from AI service
[INFO] Attempting to parse subtasks object from text response...
[INFO] Extracted JSON content from Markdown code block.
[ERROR] Failed to parse JSON object: Unexpected token 'y', "typescript\"... is not valid JSON
[ERROR] Problematic JSON string (first 500 chars): typescript\n// Example implementation\nexport interface RequestOptions extends RequestInit {\n baseUrl?: string;\n headers?: Record<string, string>;\n params?: Record<string, string>;\n timeout?: number;\n auth?: {\n type: 'bearer' | 'basic' | 'apiKey';\n token?: string;\n username?: string;\n password?: string;\n headerName?: string;\n };\n}\n\nexport class HttpClient {\n private baseUrl: string;\n private defaultOptions: RequestOptions;\n\n constructor(baseUrl: string =
[ERROR] Original Raw Response (first 500 chars): {
"subtasks": [
{
"id": 1,
"title": "Implement Core HTTP Client with Authentication",
"description": "Create a base HTTP client wrapper around fetch API with authentication support",
"dependencies": [],
"details": "1. Create TypeScript interfaces for request/response types\n2. Implement a base HttpClient class with methods for GET, POST, PUT, DELETE\n3. Add authentication handling (Bearer token, Basic auth, API key)\n4. Support request/response interceptors\n5
[ERROR] Error during AI call or parsing for task 3: Failed to parse JSON response object: Unexpected token 'y', "typescript\"... is not valid JSON
[ERROR] Error expanding task 3: Failed to parse JSON response object: Unexpected token 'y', "typescript\"... is not valid JSON
Error expanding task 3: Failed to parse JSON response object: Unexpected token 'y', "typescript\"... is not valid JSON
Expected Behavior
Should expand the task
Actual Behavior
It's currently erroring
Screenshots or Logs
See above
Environment
- Task Master version: 0.13.2
- Node.js version: v22.14.0
- Operating system: MacOS
- IDE (if applicable): CLI
Additional Context
Running CLI command
Which AI are you using ?
I get this too when using Gemini Flash 2.5 Thinking
I meant what does your mcp.json config look like and .taskmasterconfig ?
I meant what does your mcp.json config look like and .taskmasterconfig ?
I was having the same error as OP, but based on your reply I changed the maxTokens, since it was in 120k, to 1kk and now its working, in my case (gemini-2.5-pro-exp-03-25)
I'm having the same issue, using gemini-2.5-pro-exp-03-25:
Error: Failed to parse JSON response object: Unexpected end of JSON input
And even claude-3-7-sonnet-20250219:
Failed to parse JSON response object: Unexpected token p in JSON at position 0
TBH, when using with the MCP through Cursor, I'm not facing this issue. This occurred when I was using the task-master as stated in step 2.
im facing the same issue with gemini-2.5-flash-preview-04.
[ERROR] Error during AI call or parsing for task 9: Failed to parse JSON response object: Unexpected token i in JSON at position 394 [ERROR] Error expanding task 9: Failed to parse JSON response object: Unexpected token i in JSON at position 394 Error expanding task 9: Failed to parse JSON response object: Unexpected token i in JSON at position 394
i get this too using gemini-2.5-pro-preview. is there a way around it?
Feels like a lot of this has been fixed in past releases, definitely improved in 0.18.0. If the issue persists, please create a new issue
I'm facing the exact same issue, does anyone find any solutions?
mode: gemini-2.5-flash-preview-04-17
@craftgear could you give us your error ?
@craftgear I would ask you to create a separate issue since I feel like this was resolved, and you're probably running into a different type of issue
@Crunchyman-ralph Hey, thanks for chiming in. Got it, I'm gonna open an new issue.
FYI, Here is what I get anyway.
[ERROR] Advanced extraction: Failed to parse JSON object: Unexpected token '`', "```json
{
"... is not valid JSON
[ERROR] Advanced extraction: Problematic JSON string for parse (first 500 chars): ```json
{
"subtasks": [
{
"id": 1,
"title": "Install Markdown Parser Library",
"description": "Add the chosen Markdown parser library (e.g., `marked.js`) to the project dependencies.",
"dependencies": [],
"details": "Use npm or yarn to install the library: `npm install marked` or `yarn add marked`. Ensure it's added to the project's `package.json`.",
[ERROR] Error during AI call or parsing for task 3: Failed to parse JSON response object after both simple and advanced attempts: Unexpected token '`', "```json
{
"... is not valid JSON
[ERROR] Error expanding task 3: Failed to parse JSON response object after both simple and advanced attempts: Unexpected token '`', "```json
{
"... is not valid JSON
[ERROR] Failed to expand task 3: Failed to parse JSON response object after both simple and advanced attempts: Unexpected token '`', "```json
{
"... is not valid JSON