{"record":{"id":"1c73bf3ff8fba7a0","repo":"MemPalace/mempalace","slug":"empty-response-from-ollama-model-self-model","errorCode":null,"errorMessage":"Empty response from Ollama (model={self.model})","messagePattern":"Empty response from Ollama \\(model=(.+?)\\)","errorType":"exception","errorClass":"LLMError","httpStatus":null,"severity":"error","filePath":"mempalace/llm_client.py","lineNumber":270,"sourceCode":"            \"messages\": [\n                {\"role\": \"system\", \"content\": system},\n                {\"role\": \"user\", \"content\": user},\n            ],\n            \"stream\": False,\n            \"options\": options,\n        }\n        if json_mode:\n            body[\"format\"] = \"json\"\n        if think is not None:\n            # Ollama 0.7+ supports `think` for thinking-capable models (Qwen 3\n            # family, DeepSeek-R1). Pure-instruct models ignore it. We forward\n            # only when the caller explicitly opts in/out so the wire format\n            # stays minimal for the common case.\n            body[\"think\"] = think\n        data = _http_post_json(f\"{self.endpoint}/api/chat\", body, headers={}, timeout=self.timeout)\n        text = (data.get(\"message\") or {}).get(\"content\", \"\")\n        if not text:\n            raise LLMError(f\"Empty response from Ollama (model={self.model})\")\n        return LLMResponse(text=text, model=self.model, provider=self.name, raw=data)\n\n\n# ==================== OPENAI-COMPAT ====================\n\n\nclass OpenAICompatProvider(LLMProvider):\n    \"\"\"Any OpenAI-compatible ``/v1/chat/completions`` endpoint.\n\n    Supply ``--llm-endpoint http://host:port`` (with or without ``/v1``).\n    API key via ``--llm-api-key`` or the ``OPENAI_API_KEY`` env var.\n    \"\"\"\n\n    name = \"openai-compat\"\n\n    def __init__(\n        self,\n        model: str,","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/llm_client.py#L252-L288","documentation":"LLMError raised by OllamaProvider.classify() when the /api/chat response parses but message.content is missing or empty. Ollama returns HTTP 200 with an empty content field in several edge cases, so the provider treats empty output as a hard failure rather than returning ''.","triggerScenarios":"Calling classify() with json_mode=True on a model that emits nothing but a think block (thinking models with think enabled and no final answer); a model that responds entirely via tool_calls; content genuinely empty because the prompt produced no tokens.","commonSituations":"Using Qwen3/DeepSeek-R1 style models where `think` is forwarded and the model spends the whole budget reasoning; num_ctx too small so the model degenerates; wrong tag pulled (a model that answers in an unexpected field); json mode on a model with weak instruction following.","solutions":["Reproduce with `ollama run <model>` and the same prompt to see what the model actually emits","For thinking models, pass think explicitly or increase the response budget so a final answer is produced","Try a stronger instruct model (e.g. llama3.1/qwen2.5 instruct tags) for classification","Disable json_mode to check whether format constraints are suppressing output"],"exampleFix":"# before\nresp = provider.classify(system, user, json_mode=True)  # Empty response from Ollama (model=qwen3:8b)\n\n# after\nresp = provider.classify(system, user, json_mode=True, think=False)  # force a direct answer","handlingStrategy":"retry","validationCode":"ok, reason = provider.check_available()\nif not ok:\n    raise RuntimeError(f\"Ollama not ready: {reason}\")","typeGuard":null,"tryCatchPattern":"from mempalace.llm_client import LLMError\n\nfor attempt in range(2):\n    try:\n        return provider.classify(system, user, json_mode=True, think=False)\n    except LLMError as e:\n        if \"Empty response\" in str(e) and attempt == 0:\n            continue\n        raise","preventionTips":["Use instruct models for classification, not raw reasoning models","Pin model tags you have tested (avoid :latest drift)","Keep prompts explicit: 'Respond with JSON matching the schema' when json_mode is on"],"tags":["llm","ollama","empty-response","models"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}