{"record":{"id":"aa49d65b2094ae7a","repo":"Fosowl/agenticSeek","slug":"no-choices-in-lm-studio-response-result","errorCode":null,"errorMessage":"No choices in LM Studio response: {result}","messagePattern":"No choices in LM Studio response: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":399,"sourceCode":"            \"model\": self.model\n        }\n\n        try:\n            response = requests.post(route_start, json=payload, timeout=30)\n            if response.status_code != 200:\n                raise Exception(f\"LM Studio returned status {response.status_code}: {response.text}\")\n            if not response.text.strip():\n                raise Exception(\"LM Studio returned empty response\")\n            try:\n                result = response.json()\n            except ValueError as json_err:\n                raise Exception(f\"Invalid JSON from LM Studio: {response.text[:200]}\") from json_err\n\n            if verbose:\n                print(\"Response from LM Studio:\", result)\n            choices = result.get(\"choices\", [])\n            if not choices:\n                raise Exception(f\"No choices in LM Studio response: {result}\")\n\n            message = choices[0].get(\"message\", {})\n            content = message.get(\"content\", \"\")\n            if not content:\n                raise Exception(f\"Empty content in LM Studio response: {result}\")\n            return content\n\n        except requests.exceptions.Timeout:\n            raise Exception(\"LM Studio request timed out - check if server is responsive\")\n        except requests.exceptions.ConnectionError:\n            raise Exception(f\"Cannot connect to LM Studio at {route_start} - check if server is running\")\n        except requests.exceptions.RequestException as e:\n            raise Exception(f\"HTTP request failed: {str(e)}\") from e\n        except Exception as e:\n            if \"LM Studio\" in str(e):\n                raise  # Re-raise our custom exceptions\n            raise Exception(f\"Unexpected error: {str(e)}\") from e\n","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L381-L417","documentation":"After parsing JSON, lm_studio_fn reads result.get('choices', []) and raises this if the list is missing or empty, embedding the full parsed result. LM Studio replied with valid JSON but not a chat-completion-shaped object.","triggerScenarios":"Parsed JSON lacks a non-empty 'choices' array — e.g. an OpenAI-style error object {\"error\": {...}}, an embeddings response, or a nonstandard server response.","commonSituations":"LM Studio returned a JSON error payload with status 200; the endpoint is /v1/completions (legacy shape with 'choices' sometimes missing or the model errored); misconfigured route in config.ini.","solutions":["Log the embedded `result` in the message to see what LM Studio actually returned","If result contains an 'error' key, address that upstream cause (model not loaded, context overflow)","Ensure route_start targets /v1/chat/completions, not /v1/completions or /v1/embeddings","Confirm the model is fully loaded before sending requests","Retry once — some LM Studio versions emit transient error JSON under load"],"exampleFix":"// before\nclient = requests.post(\"http://localhost:1234/v1/embeddings\", json=payload)\n// after\nclient = requests.post(\"http://localhost:1234/v1/chat/completions\", json=payload)","handlingStrategy":"type-guard","validationCode":"def check_lm_studio_shape(sample_fn, history):\n    import json\n    raw = None\n    try:\n        result = sample_fn(history)\n    except Exception as e:\n        if \"No choices\" in str(e):\n            raise SystemExit(\"LM Studio not returning chat completions — check endpoint/model\")","typeGuard":"def has_choices(result) -> bool:\n    return isinstance(result, dict) and isinstance(result.get(\"choices\"), list) and len(result[\"choices\"]) > 0","tryCatchPattern":"try:\n    content = provider.lm_studio_fn(history)\nexcept Exception as e:\n    if \"No choices in LM Studio response\" in str(e):\n        payload = str(e).split(\": \", 1)[-1]\n        if '\"error\"' in payload:\n            handle_upstream_error(payload)\n        else:\n            verify_endpoint_is_chat_completions()\n    else:\n        raise","preventionTips":["Verify the endpoint returns OpenAI chat-completion shape before wiring it in","If the embedded result has an 'error' key, fix that root cause first","Keep LM Studio updated — response shapes have changed across versions","Test with a minimal one-message request during setup"],"tags":["lm-studio","schema","response-shape","local-server"],"backgroundTag":"unexpected-response-schema","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}