Fosowl/agenticSeek · error · Exception

Empty content in LM Studio response: {result}

Error message

Empty content in LM Studio response: {result}

What it means

lm_studio_fn extracts choices[0].message.content and raises this when the content string is empty, including the whole result. The response shape is valid but the model produced no text (e.g. it emitted only a tool call, or generation was cut off).

Source

Thrown at sources/llm_provider.py:404

            if response.status_code != 200:
                raise Exception(f"LM Studio returned status {response.status_code}: {response.text}")
            if not response.text.strip():
                raise Exception("LM Studio returned empty response")
            try:
                result = response.json()
            except ValueError as json_err:
                raise Exception(f"Invalid JSON from LM Studio: {response.text[:200]}") from json_err

            if verbose:
                print("Response from LM Studio:", result)
            choices = result.get("choices", [])
            if not choices:
                raise Exception(f"No choices in LM Studio response: {result}")

            message = choices[0].get("message", {})
            content = message.get("content", "")
            if not content:
                raise Exception(f"Empty content in LM Studio response: {result}")
            return content

        except requests.exceptions.Timeout:
            raise Exception("LM Studio request timed out - check if server is responsive")
        except requests.exceptions.ConnectionError:
            raise Exception(f"Cannot connect to LM Studio at {route_start} - check if server is running")
        except requests.exceptions.RequestException as e:
            raise Exception(f"HTTP request failed: {str(e)}") from e
        except Exception as e:
            if "LM Studio" in str(e):
                raise  # Re-raise our custom exceptions
            raise Exception(f"Unexpected error: {str(e)}") from e

    def openrouter_fn(self, history, verbose=False):
        """
        Use OpenRouter API to generate text.
        """
        client = OpenAI(api_key=self.api_key, base_url="https://openrouter.ai/api/v1")

View on GitHub (pinned to ae57a23577)

Solutions

  1. Print the embedded `result` and inspect message fields (tool_calls, reasoning_content) for output placed elsewhere
  2. Increase max_tokens in the payload and check finish_reason — 'length' means generation was truncated
  3. Re-load the model in LM Studio with the correct chat template/preset
  4. Ensure `history` messages use proper roles (system/user/assistant) for the loaded model
  5. Retry with a different model to rule out a template/format incompatibility

Example fix

// before
payload = {"messages": history, "max_tokens": 16}
// after
payload = {"messages": history, "max_tokens": 1024, "temperature": 0.7}
Defensive patterns

Strategy: validation

Validate before calling

def validate_history(history):
    assert history, "history must not be empty"
    assert all(isinstance(m, dict) and m.get("role") in ("system", "user", "assistant") and isinstance(m.get("content"), str) for m in history), "Malformed chat messages for LM Studio"

Type guard

def content_is_nonempty(result) -> bool:
    try:
        return bool(result["choices"][0]["message"]["content"])
    except (KeyError, IndexError, TypeError):
        return False

Try / catch

try:
    content = provider.lm_studio_fn(history)
except Exception as e:
    if "Empty content" in str(e):
        result = json.loads(str(e).split(": ", 1)[-1])
        tool_calls = result.get("choices", [{}])[0].get("message", {}).get("tool_calls")
        if tool_calls:
            handle_tool_calls(tool_calls)
        else:
            raise_model_template_error()
    else:
        raise

Prevention

When it happens

Trigger: choices[0].message.content is '' or missing: model returned only reasoning/tool-call fields, stop token hit immediately, or the loaded template's chat template mismatch produced no text.

Common situations: Using a chat template/model whose prompt format doesn't match history messages; max_tokens too small (all budget consumed by reasoning); LM Studio model loaded with an incompatible template; tool-calling enabled consuming the content field.

Related errors


AI-assisted analysis of Fosowl/agenticSeek@ae57a23577 (2026-08-30). Data as JSON: /api/errors/3af7a23f2a3162cc. Report an issue: GitHub.