{"record":{"id":"d307c1efbe810fc7","repo":"plandex-ai/plandex","slug":"error-unmarshalling-plan-description-response-v","errorCode":null,"errorMessage":"error unmarshalling plan description response: %v","messagePattern":"error unmarshalling plan description response: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/model/plan/commit_msg.go","lineNumber":159,"sourceCode":"\n\t\tif content == \"\" {\n\t\t\tfmt.Println(\"no describePlan function call found in response\")\n\n\t\t\tgo notify.NotifyErr(notify.SeverityError, fmt.Errorf(\"no describePlan function call found in response\"))\n\n\t\t\treturn nil, &shared.ApiError{\n\t\t\t\tType:   shared.ApiErrorTypeOther,\n\t\t\t\tStatus: http.StatusInternalServerError,\n\t\t\t\tMsg:    \"No describePlan function call found in response. The model failed to generate a valid response.\",\n\t\t\t}\n\t\t}\n\n\t\tvar desc shared.ConvoMessageDescription\n\t\terr = json.Unmarshal([]byte(content), &desc)\n\t\tif err != nil {\n\t\t\tfmt.Printf(\"Error unmarshalling plan description response: %v\\n\", err)\n\n\t\t\tgo notify.NotifyErr(notify.SeverityError, fmt.Errorf(\"error unmarshalling plan description response: %v\", err))\n\n\t\t\treturn nil, &shared.ApiError{\n\t\t\t\tType:   shared.ApiErrorTypeOther,\n\t\t\t\tStatus: http.StatusInternalServerError,\n\t\t\t\tMsg:    fmt.Sprintf(\"error unmarshalling plan description response: %v\", err),\n\t\t\t}\n\t\t}\n\t\tcommitMsg = desc.CommitMsg\n\t}\n\n\treturn &db.ConvoMessageDescription{\n\t\tPlanId:    planId,\n\t\tCommitMsg: commitMsg,\n\t}, nil\n}\n\ntype GenCommitMsgForPendingResultsParams struct {\n\tAuth      *types.ServerAuth","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/plan/commit_msg.go#L141-L177","documentation":"After receiving the model's content in the non-XML path, genPlanDescription expects it to be JSON matching shared.ConvoMessageDescription and unmarshals it. If the content is not valid JSON (or has the wrong shape), json.Unmarshal fails and the server returns this 500 ApiError.","triggerScenarios":"The model returned prose or malformed JSON instead of the expected structured description; a proxy concatenated extra text around the JSON; the response was truncated mid-JSON by max_tokens; a provider returned an error page/body captured as content.","commonSituations":"Local/partially-tuned models producing trailing commas or comments; responses wrapped in Markdown code fences (```json ... ```) that break strict unmarshalling; long conversations hitting token limits and truncating the JSON.","solutions":["Use a model that reliably emits strict JSON for tool responses","Increase max_tokens to avoid truncated JSON and retry","Strip code fences/whitespace before parsing (server-side patch) or prefer the XML/tool path","Retry the request — malformed output is often intermittent"],"exampleFix":"// before: trusting raw content\nvar desc shared.ConvoMessageDescription\nerr = json.Unmarshal([]byte(content), &desc)\n// after: strip common wrappers first\ntrimmed := strings.TrimSpace(strings.Trim(content, \"` \\n\"))\ntrimmed = strings.TrimPrefix(strings.TrimPrefix(trimmed, \"json\"), \"\\n\")\nerr = json.Unmarshal([]byte(trimmed), &desc)","handlingStrategy":"validation","validationCode":"// validate JSON shape before unmarshalling into the struct\ntrimmed := strings.TrimSpace(content)\nif !strings.HasPrefix(trimmed, \"{\") || !json.Valid([]byte(trimmed)) {\n    return fmt.Errorf(\"model content is not valid JSON\")\n}","typeGuard":null,"tryCatchPattern":"desc, apiErr := genPlanDescription(...)\nif apiErr != nil && strings.Contains(apiErr.Msg, \"unmarshalling plan description\") {\n    // retry once; intermittent malformed output\n    return genPlanDescription(...)\n}","preventionTips":["Prefer tool-call/function output over asking the model for free-form JSON","Increase max_tokens to avoid mid-JSON truncation","Strip code fences before parsing when using proxies or local models","Retry once on unmarshal failure — malformed output is often intermittent"],"tags":["llm","json-parsing","model-output"],"backgroundTag":"schema-validation-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}