mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[GH-ISSUE #19098] issue: Prompt & context duplication when RAG template is used #34301
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 @matiboux on GitHub (Nov 11, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/19098
Check Existing Issues
Installation Method
Git Clone
Open WebUI Version
v0.6.36
Ollama Version (if applicable)
No response
Operating System
Ubuntu 24.04 LTS (WSL2)
Browser (if applicable)
No response
Confirmation
README.md.Expected Behavior
When a tool is selected and invoked by the model, the prompt sent to the model should be the message formatted from the RAG template, which contains the context (tool results) and the user prompt.
Actual Behavior
When a tool is selected and used by the model, the prompt sent to the model is the message formatted from the RAG template prepended to the existing user message. The RAG template includes both the context (tool results) and the user prompt, but the existing user message also contains these, resulting in duplicated context and instructions.
Steps to Reproduce
npm run devto start the frontend.sh dev.shfrom thebackend/directory to start the backend./chat/completionsendpoint to a real OpenAI-compatible API, and whose only other role is to print out:Note: Alternatively, you could add logs in the backend to print the request parameters, but using a custom API ensures backend code is untouched for this test.
Logs & Screenshots
Below are actual outputs from the custom API proxy used during testing. These show message flow and context duplication during tool invocation.
Tool Selection Request:
LLM Chat Query:
Additional Information
Related code responsible for the duplication:
Prepends the RAG template formatted text before the prompt in the user message:
backend/open_webui/utils/middleware.py#L1493-L1502
Appends the tool result context to the user message, duplicating it as well:
backend/open_webui/utils/middleware.py#L484-L488
I will create a PR to attempt to resolve this issue.
Note: My testing focused on RAG template use in conjunction with tools. I have not evaluated RAG template behavior with documents.
@matiboux commented on GitHub (Nov 11, 2025):
The PR #19099 attempts to resolve the issue without modifying this code block:
e0d5de1697/backend/open_webui/utils/middleware.py (L484-L488)This code block seems out of place, given the comment above it stating that it is for the case when "citation is not enabled for this tool". However, it is executed regardless of that condition, at the same time as the neighboring code for when "citation is enabled for this tool".
After the changes made in PR #19099, the user message is now overwritten using the RAG template, so this code block does not have an effect in that context.
It is recommended that this code block be reviewed to determine if it is still necessary or if it could potentially introduce issues in other scenarios.