{"record":{"id":"7c04d00cd4455b93","repo":"Mintplex-Labs/anything-llm","slug":"ollama-getchatcompletion-text-response-was-empty","errorCode":null,"errorMessage":"Ollama::getChatCompletion text response was empty.","messagePattern":"Ollama::getChatCompletion text response was empty\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/ollama/index.js","lineNumber":305,"sourceCode":"          return {\n            content,\n            usage: {\n              prompt_tokens: res.prompt_eval_count,\n              completion_tokens: res.eval_count,\n              total_tokens: res.prompt_eval_count + res.eval_count,\n              duration: res.eval_duration / 1e9,\n            },\n          };\n        })\n        .catch((e) => {\n          throw new Error(\n            `Ollama::getChatCompletion failed to communicate with Ollama. ${this.#errorHandler(e).message}`\n          );\n        })\n    );\n\n    if (!result.output.content || !result.output.content.length)\n      throw new Error(`Ollama::getChatCompletion text response was empty.`);\n\n    return {\n      textResponse: result.output.content,\n      metrics: {\n        prompt_tokens: result.output.usage.prompt_tokens,\n        completion_tokens: result.output.usage.completion_tokens,\n        total_tokens: result.output.usage.total_tokens,\n        outputTps:\n          result.output.usage.completion_tokens / result.output.usage.duration,\n        duration: result.output.usage.duration,\n        model: this.model,\n        provider: this.className,\n        timestamp: new Date(),\n      },\n    };\n  }\n\n  async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/ollama/index.js#L287-L323","documentation":"Post-success validation: the Ollama chat call resolved with HTTP OK and a parsed body, but result.output.content is falsy or an empty string. Indicates the model produced zero output characters even though no error was thrown. Thrown after the .catch, so it only fires on a structurally-valid but empty response.","triggerScenarios":"Model returns message.content === '' (empty); reasoning model emits only thinking with no final content and the thinking-wrap path leaves content empty; an embedding-only model mistakenly used for chat; model interrupted/aborted internally without error; prompt triggers an empty-string refusal.","commonSituations":"Accidentally selecting an embedding model (e.g. nomic-embed-text) as the chat LLM; a buggy/under-trained local model; tool-call-only model returning no text; quantization artifact producing empty output; context fully truncated so the model has nothing to respond to.","solutions":["Retry the exact prompt; if consistently empty, the model is the likely culprit.","Verify this.model is a chat/instruct model, not an embedding model ('ollama show <model>').","Reproduce with 'ollama run <model>' directly on the server to isolate AnythingLLM.","Switch to a known-good chat model to confirm the provider wiring is correct."],"exampleFix":"// before\nif (!result.output.content || !result.output.content.length)\n  throw new Error(`Ollama::getChatCompletion text response was empty.`);\n\n// after - surface what was returned for debugging\nif (!result.output.content || !result.output.content.length)\n  throw new Error(`Ollama::getChatCompletion text response was empty for model ${this.model}. Check that it is a chat model and produced output. Raw usage: ${JSON.stringify(result.output.usage)}`);","handlingStrategy":"fallback","validationCode":"const isChatModel = async (client, model) => {\n  const info = await client.show({ model });\n  return !info.capabilities?.includes('embedding');\n};\nif (!(await isChatModel(llm.client, llm.model)))\n  throw new Error(`${llm.model} is not a chat model; cannot produce text responses.`);","typeGuard":"const hasNonEmptyContent = (o) =>\n  !!o && typeof o.content === 'string' && o.content.length > 0;","tryCatchPattern":"try {\n  const r = await llm.getChatCompletion(messages, { temperature });\n  if (!r?.textResponse) return fallbackResponse();\n  return r;\n} catch (e) {\n  if (e.message.includes('text response was empty')) return fallbackResponse();\n  throw e;\n}","preventionTips":["Never select an embedding model as the chat LLM.","Reproduce suspect prompts with 'ollama run' to isolate model issues.","Provide a fallback/clarification response when the model returns empty."],"tags":["ollama","llm-provider","empty-response","validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}