mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 11:28:35 -05:00
[GH-ISSUE #21663] issue: RAG template mutates web search tool call args #35079
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @relic664 on GitHub (Feb 20, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/21663
Check Existing Issues
Installation Method
Docker
Open WebUI Version
v0.8.3
Ollama Version (if applicable)
No response
Operating System
Alpine 3.23
Browser (if applicable)
No response
Confirmation
README.md.Expected Behavior
RAG templating should not leak into tool call arguments.
Actual Behavior
RAG_SYSTEM_CONTEXTcontrols where RAG context is injected, not whether templating occurs (it's always applied when sources exist). The problem is that it's currently injected into the user message during native tool-calling. During loops, this can cause the RAG template to be injected into subsequent tool call args (especially in the case of multiple tool calls per turn). It would be safer to inject into the system message instead.Steps to Reproduce
Logs & Screenshots
Additional Information
When apply_source_context_to_messages was added in
2789f6a24d, it reused the existing RAG-context mechanism for tool sources. Current behavior is that whenever there are sources (from knowledge retrieval or tool-call citations), they are wrapped in tags and RAG_TEMPLATE via rag_template, then injected back into conversation context. RAG_SYSTEM_CONTEXT only changes placement (system vs user), not whether this wrapping occurs. This causes issues in native tool-calling loops where multiple calls may happen in one turn while tool arguments are still being generated, leading to template text leaking into subsequent tool arguments.I'm willing to draft a PR to patch this if there's interest.
@Classic298 commented on GitHub (Feb 20, 2026):
huh. How do i reproduce this? I have never seen this before and i have been using native tool calling for search_web many many times before.
What model is this? Are you sure the model didn't just hallucinate and input the RAG system prompt into the search_web as the actualy query of the tool call?
When i try to reproduce, it just works as intended.
Need ways to reproduce this. Might also just be model dependent behaviour. I have never seen this happen.
@relic664 commented on GitHub (Feb 20, 2026):
This screenshot doesn't dismiss the issue at hand as the issue is multiple concurrent
search_webturns. Try your query again, but set sources returned to 1 instead of 5 in your web search settings to induce multiple calls sequentially.@Classic298 commented on GitHub (Feb 20, 2026):
@relic664 the screenshot is just an example. I have had models do 30 search_web tool calls back-to-back with the right deep research prompts. It simply never happened to me. Can you please answer the questions I asked? The issue might be elsewhere.
@Classic298 commented on GitHub (Feb 20, 2026):
I will do a code investigation here just in case, but the RAG prompt ... being injected into the tool call args as you say sound impossible.
@relic664 commented on GitHub (Feb 20, 2026):
I was able to reproduce with minimax2.5
@Classic298 commented on GitHub (Feb 20, 2026):
Ok i have found something interesting
The rag prompt is NOT injected into the tool call, the model is indeed just stupid
but Open WebUI IS also mishandling the Rag system prompt.
I will draft up a fix for what i found.
@relic664 commented on GitHub (Feb 20, 2026):
In my case, I did a quick test and just shoved it in the system message instead of the user message and it worked fine. It was a three line fix, FWIW
@Classic298 commented on GitHub (Feb 20, 2026):
properly fixing it is a bit more than three lines.
I am drafting up a PR right now.
Currently testing it. If it works, i will submit it in a few minutes
@Classic298 commented on GitHub (Feb 20, 2026):
ok have a fix
@Classic298 commented on GitHub (Feb 20, 2026):
https://github.com/open-webui/open-webui/pull/21668
@Classic298 commented on GitHub (Feb 22, 2026):
Fixed in dev testing wanted
@relic664 commented on GitHub (Feb 23, 2026):
I checked on
git-824eebaand its still broken there for me.@Classic298 commented on GitHub (Feb 23, 2026):
@relic664 sorry can you tell me what commit you are on now? The gist of the docker is different to that.
Can you see if the changes are applied?
@relic664 commented on GitHub (Feb 23, 2026):
I just pulled the latest dev and it corresponds to
d9fd2a3f. The issue is still cropping up for me on that image. (now docker taggit-d9fd2a3)@relic664 commented on GitHub (Feb 23, 2026):
Here's the diff for the patch that has been working for me, if it helps.
@Classic298 commented on GitHub (Feb 23, 2026):
Feel free to reopen if still the case with 0.8.5
make sure to include logs that prove the RAG prompt is indeed being sent multiple times to the model still
Thanks!
@relic664 commented on GitHub (Feb 23, 2026):
The issue still persists in 0.8.5 (looks like I don't have permission to reopen the issue)
@Classic298 commented on GitHub (Feb 23, 2026):
@relic664 i meant open a new issue if still reproducible. Do ensure you include your own logging that shows that the RAG prompt is still being concatenated into multiple prompts instead of just once prompt.
Also please ensure you are indeed running the latest version, not that docker is playing a trick on you. @silentoplayz tested this yesterday with 30+ web search calls WITH the fix in place and couldn't reproduce. While you can with just 3 tool uses.
Something is fishy here