odysseus-dev/odysseus · error · HTTPException
AI returned invalid JSON for auto-sort — the model may not f
Error message
AI returned invalid JSON for auto-sort — the model may not follow JSON instructions; try a different utility model in Settings.
What it means
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.
Source
Thrown at routes/session_routes.py:1260
except json.JSONDecodeError:
continue
return None
result = _loads_lenient(text)
# Markdown code fence
if result is None:
fence_match = re.search(r'```(?:json)?\s*\n?([\s\S]*?)```', text)
if fence_match:
result = _loads_lenient(fence_match.group(1).strip())
# First { … last } block
if result is None:
brace_start = text.find('{')
brace_end = text.rfind('}')
if brace_start >= 0 and brace_end > brace_start:
result = _loads_lenient(text[brace_start:brace_end + 1])
if result is None:
logger.error(f"Auto-sort: could not parse JSON from: {text[:500]}")
raise HTTPException(502, "AI returned invalid JSON for auto-sort — the model may not follow JSON instructions; try a different utility model in Settings.")
except HTTPException:
raise
except Exception as e:
logger.error(f"Auto-sort LLM call failed: {e}")
raise HTTPException(502, f"Auto-sort failed: {str(e)}")
folders = result.get("folders", {})
if not folders:
return {"status": "skipped", "reason": "AI found no groupings"}
# Build id -> folder map
id_prefix_map = {s["id"][:8]: s["id"] for s in session_list}
assignments = {}
for folder_name, ids in folders.items():
for sid_or_prefix in ids:
# Match by full ID or prefix
full_id = None
if sid_or_prefix in id_prefix_map.values():View on GitHub (pinned to f9235ebbf1)
Solutions
- Try a different utility model in Settings that follows JSON instructions.
- Retry auto-sort; the model output may parse on a second attempt.
When it happens
Trigger: 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.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14).
Data as JSON: /api/errors/51a21f4629e29d15.
Report an issue: GitHub.