{"record":{"id":"51a21f4629e29d15","repo":"odysseus-dev/odysseus","slug":"ai-returned-invalid-json-for-auto-sort-the-model","errorCode":null,"errorMessage":"AI returned invalid JSON for auto-sort — the model may not follow JSON instructions; try a different utility model in Settings.","messagePattern":"AI returned invalid JSON for auto-sort — the model may not follow JSON instructions; try a different utility model in Settings\\.","errorType":"http","errorClass":"HTTPException","httpStatus":502,"severity":"error","filePath":"routes/session_routes.py","lineNumber":1260,"sourceCode":"                    except json.JSONDecodeError:\n                        continue\n                return None\n\n            result = _loads_lenient(text)\n            # Markdown code fence\n            if result is None:\n                fence_match = re.search(r'```(?:json)?\\s*\\n?([\\s\\S]*?)```', text)\n                if fence_match:\n                    result = _loads_lenient(fence_match.group(1).strip())\n            # First { … last } block\n            if result is None:\n                brace_start = text.find('{')\n                brace_end = text.rfind('}')\n                if brace_start >= 0 and brace_end > brace_start:\n                    result = _loads_lenient(text[brace_start:brace_end + 1])\n            if result is None:\n                logger.error(f\"Auto-sort: could not parse JSON from: {text[:500]}\")\n                raise HTTPException(502, \"AI returned invalid JSON for auto-sort — the model may not follow JSON instructions; try a different utility model in Settings.\")\n        except HTTPException:\n            raise\n        except Exception as e:\n            logger.error(f\"Auto-sort LLM call failed: {e}\")\n            raise HTTPException(502, f\"Auto-sort failed: {str(e)}\")\n\n        folders = result.get(\"folders\", {})\n        if not folders:\n            return {\"status\": \"skipped\", \"reason\": \"AI found no groupings\"}\n\n        # Build id -> folder map\n        id_prefix_map = {s[\"id\"][:8]: s[\"id\"] for s in session_list}\n        assignments = {}\n        for folder_name, ids in folders.items():\n            for sid_or_prefix in ids:\n                # Match by full ID or prefix\n                full_id = None\n                if sid_or_prefix in id_prefix_map.values():","sourceCodeStart":1242,"sourceCodeEnd":1278,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/routes/session_routes.py#L1242-L1278","documentation":"Error \"AI returned invalid JSON for auto-sort — the model may not follow JSON instructions; try a different utility model in Settings.\" thrown in odysseus-dev/odysseus.","triggerScenarios":"Triggered when the corresponding server-side validation or runtime check at the recorded location rejects the request or operation and returns this error message to the caller.","commonSituations":"See trigger scenarios.","solutions":["Try a different utility model in Settings that follows JSON instructions.","Retry auto-sort; the model output may parse on a second attempt."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}