Ollama 500 "no user query found in messages"
Last checked
The error
chat prompt error: no user query found in messages
{"type":"error","error":{"type":"api_error","message":"no user query found in messages"}}The first line is the Ollama server log. The second is the HTTP 500 body on the Anthropic-compatible /v1/messages endpoint. /api/chat clients show the same text with status code 500.
The model's chat template (Qwen3.8 and MiniCPM-V 4.7 among them) raises an error when the message list it receives has no user message with text in it, and Ollama returns that as a 500. Two things cause it: Ollama trimmed the oldest messages to fit num_ctx and the user message was among them, or your agent sent a turn with only tool results or system text. Raise the context length (agents need at least 64000) and make sure every request carries a user message.
Why it happens
Templates such as Qwen3.8's contain raise_exception('No user query found in messages.'). When Ollama renders a request whose message list has no plain user turn, the template throws and the request fails with HTTP 500.
- Context overflow. When the conversation outgrows num_ctx, Ollama prunes older messages, and the user message can be dropped. A maintainer gave this as the cause on ollama/ollama#17778 (qwen3.8 tool loops at about 205k context).
- A tool-only turn. An assistant tool call followed by a turn that holds only the tool result, with no user text, fails on both /v1/messages and /v1/chat/completions (ollama/ollama#18303, Ollama 0.33.0). A user turn with empty text fails the same way. The same thing is reported from the OpenFox harness (co-l/openfox#397).
- A small default context. Ollama sets the default from VRAM: 4k under 24 GiB, 32k at 24 to 48 GiB, 256k at 48 GiB and above. On a smaller card an agent fills 4k quickly.
- Generic Ollama 500s that are not this error: "model not found", out of memory, or a model that failed to load. The message text tells them apart; see the related pages.
The fix
- 1 Confirm the error in the Ollama server log: look for chat prompt error: no user query found in messages.
- 2 Raise the context for the server: OLLAMA_CONTEXT_LENGTH=64000 ollama serve. Ollama's docs recommend at least 64000 for agents and coding tools.
- 3 Or set it per model in a Modelfile with PARAMETER num_ctx 64000, then ollama create a new tag from it. In ollama run you can test with /set parameter num_ctx 64000.
- 4 Make sure your harness sends a user message with text. If it continues a tool loop with only tool results, have it add a short user turn, or compact history before it outgrows the context.
- 5 Retry the same request. If it still fails with plenty of context, try a model whose template allows tool-only continuations, and watch the open pull requests (#17813, #17894, #18697) that change how Ollama handles this.
OLLAMA_CONTEXT_LENGTH=64000 ollama serveHas Ollama fixed it?
Not as of 10 November 2026. Issue #18303 was closed as a duplicate, #17778 is open, and the pull requests that would keep the latest user message during truncation (#17894, #18697) or tolerate transcripts without a user query (#17813) are not merged.
A maintainer's view on #17778 is that the Qwen3.8 template does not support a message list without a user message, so a tool continuation without one is not valid input. Plan for the fix to come from your harness or from more context, not from an Ollama update.
Which harnesses hit it
Any agent that runs long tool loops against Ollama can: Hermes, OpenClaw and OpenFox have all been seen with it. The same template check returns HTTP 400 "No user query found in messages." on other OpenAI-compatible servers, so the cause is the model template, not Ollama alone.
Still failing?
- "model does not support tools" instead. The model has no tool template; see that page.
- "memory layout cannot be allocated" or a crash after raising num_ctx. The larger context no longer fits in VRAM; pick a value between.
- "model not found, try pulling it first". The tag in your agent config is wrong.
Related errors
Hit a different error?
Paste any agent error and get the cause and fix in seconds.
Frequently asked questions
What does "500 no user query found in messages" mean?
The model's chat template found no user message with text in the request and raised an error, which Ollama returns as HTTP 500. Either context trimming removed the user turn, or the client sent a turn with only tool results or system text.
How do I increase num_ctx in Ollama?
For the whole server, start it with OLLAMA_CONTEXT_LENGTH=64000 ollama serve. For one model, put PARAMETER num_ctx 64000 in a Modelfile and create a new tag. Inside ollama run, /set parameter num_ctx 64000 works for that session.
What is the default Ollama context length?
It depends on VRAM: 4k below 24 GiB, 32k from 24 to 48 GiB, and 256k at 48 GiB or more. Some older Ollama docs pages still say 2048 or 4096; the context length page is the current one.
Why does Qwen 3.8 return this error?
Qwen3.8's chat template raises an exception when no user message is present. Tool loops that continue with only tool results, or long sessions where the user message was trimmed, trigger it.
Why does Ollama return a 500 error?
A 500 means the request failed inside Ollama. The message after it names the cause: no user query found, model not found, out of memory, or a model that failed to load. Each has a different fix.
Stop firefighting agent errors
Decoding errors one at a time is the manual version of what BetterClaw automates. Run your agents on a no-code AI agent platform with managed models, retries and config validation built in.
Free plan available · Pro $49/mo · BYOK · 7-day free trial
