Mintplex-Labs/anything-llm · error · Error
Ollama::getChatCompletion text response was empty.
Error message
Ollama::getChatCompletion text response was empty.
What it means
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.
Source
Thrown at server/utils/AiProviders/ollama/index.js:305
return {
content,
usage: {
prompt_tokens: res.prompt_eval_count,
completion_tokens: res.eval_count,
total_tokens: res.prompt_eval_count + res.eval_count,
duration: res.eval_duration / 1e9,
},
};
})
.catch((e) => {
throw new Error(
`Ollama::getChatCompletion failed to communicate with Ollama. ${this.#errorHandler(e).message}`
);
})
);
if (!result.output.content || !result.output.content.length)
throw new Error(`Ollama::getChatCompletion text response was empty.`);
return {
textResponse: result.output.content,
metrics: {
prompt_tokens: result.output.usage.prompt_tokens,
completion_tokens: result.output.usage.completion_tokens,
total_tokens: result.output.usage.total_tokens,
outputTps:
result.output.usage.completion_tokens / result.output.usage.duration,
duration: result.output.usage.duration,
model: this.model,
provider: this.className,
timestamp: new Date(),
},
};
}
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {View on GitHub (pinned to 526360e320)
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.
Example fix
// before
if (!result.output.content || !result.output.content.length)
throw new Error(`Ollama::getChatCompletion text response was empty.`);
// after - surface what was returned for debugging
if (!result.output.content || !result.output.content.length)
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)}`); Defensive patterns
Strategy: fallback
Validate before calling
const isChatModel = async (client, model) => {
const info = await client.show({ model });
return !info.capabilities?.includes('embedding');
};
if (!(await isChatModel(llm.client, llm.model)))
throw new Error(`${llm.model} is not a chat model; cannot produce text responses.`); Type guard
const hasNonEmptyContent = (o) => !!o && typeof o.content === 'string' && o.content.length > 0;
Try / catch
try {
const r = await llm.getChatCompletion(messages, { temperature });
if (!r?.textResponse) return fallbackResponse();
return r;
} catch (e) {
if (e.message.includes('text response was empty')) return fallbackResponse();
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Ollama::getChatCompletion failed to communicate with Ollama.
- Perplexity chat: ${this.model} is not valid for chat complet
- PPIO chat: ${this.model} is not valid for chat completion!
- Privatemode chat: ${this.model} is not valid or defined mode
- No token context limit was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/7c04d00cd4455b93.
Report an issue: GitHub.