Before submitting, make sure you've checked the following:
Target branch: Verify that the pull request targets the dev branch. Not targeting the dev branch will lead to immediate closure of the PR.
Description: Provide a concise description of the changes made in this pull request down below.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: If necessary, update relevant documentation Open WebUI Docs like environment variables, the tutorials, or other documentation sources.
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Perform manual tests to verify the implemented fix/feature works as intended AND does not break any other functionality. Take this as an opportunity to make screenshots of the feature/fix and include it in the PR description.
Agentic AI Code: Confirm this Pull Request is not written by any AI Agent or has at least gone through additional human review AND manual testing. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR.
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Title Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
fix: Bug fix or error correction
Changelog Entry
Description
This PR updates the query placeholder replacement logic in the rag_template function within backend/open_webui/utils/task.py to simplify, fix, and improve handling of [query] and {{QUERY}} placeholders.
Added
None.
Changed
Updated the query placeholder detection and substitution logic for [query] and {{QUERY}} strings in backend/open_webui/utils/task.py.
Deprecated
None.
Removed
None.
Fixed
Fixed logic errors in query placeholder escaping and unintended replacement of context values in backend/open_webui/utils/task.py.
Updated prompts were manually tested and verified using a proxy OpenAI-compatible proxy API to inspect system & user messages.
LLM Chat Query prompt with changes from this PR:
Messages since the last assistant response:
- user
```
### Task:
Respond to the user query using the provided context, incorporating inline citations in the format [id] **only when the <source> tag includes an explicit id attribute** (e.g., <source id="1">).
### Guidelines:
- If you don't know the answer, clearly state that.
- If uncertain, ask the user for clarification.
- Respond in the same language as the user's query.
- If the context is unreadable or of poor quality, inform the user and provide the best possible answer.
- If the answer isn't present in the context but you possess the knowledge, explain this to the user and provide the answer using your own understanding.
- **Only include inline citations using [id] (e.g., [1], [2]) when the <source> tag includes an id attribute.**
- Do not cite if the <source> tag does not contain an id attribute.
- Do not use XML tags in your response.
- Ensure citations are concise and directly related to the information provided.
### Example of Citation:
If the user asks about a specific topic and the information is found in a source with a provided id attribute, the response should include the citation like in the following example:
* "According to the study, the proposed method increases efficiency by 20% [1]."
### Output:
Provide a clear and direct response to the user's query, including inline citations in the format [id] only when the <source> tag with id attribute is present in the context.
<context>
<source id="1" name="test/get_current_time">{{QUERY}} [query] Current Date and Time = Tuesday, November 11, 2025, 02:02:37 AM</source>
</context>
<user_query>
what time is it?
</user_query>
what time is it?
Tool `test/get_current_time` Output: {{QUERY}} [query] Current Date and Time = Tuesday, November 11, 2025, 02:02:37 AM
```
This PR specifically addresses the code responsible for the escaping faulty logic:
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/19102
**Author:** [@matiboux](https://github.com/matiboux)
**Created:** 11/11/2025
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `fix/rag-template-query-placeholder`
---
### 📝 Commits (1)
- [`d009c9b`](https://github.com/open-webui/open-webui/commit/d009c9bd4ef6d93892339befa4ecd2b18de9ff3c) Fix template query placeholder escaping logic
### 📊 Changes
**1 file changed** (+6 additions, -10 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/utils/task.py` (+6 -10)
</details>
### 📄 Description
# Pull Request Checklist
**Before submitting, make sure you've checked the following:**
- [x] **Target branch:** Verify that the pull request targets the `dev` branch. **Not targeting the `dev` branch will lead to immediate closure of the PR.**
- [x] **Description:** Provide a concise description of the changes made in this pull request down below.
- [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [x] **Documentation:** If necessary, update relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs) like environment variables, the tutorials, or other documentation sources.
- [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] **Testing:** Perform manual tests to **verify the implemented fix/feature works as intended AND does not break any other functionality**. Take this as an opportunity to **make screenshots of the feature/fix and include it in the PR description**.
- [x] **Agentic AI Code:** Confirm this Pull Request is **not written by any AI Agent** or has at least **gone through additional human review AND manual testing**. If any AI Agent is the co-author of this PR, it may lead to immediate closure of the PR.
- [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [x] **Title Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following:
- **fix**: Bug fix or error correction
# Changelog Entry
### Description
- This PR updates the query placeholder replacement logic in the `rag_template` function within `backend/open_webui/utils/task.py` to simplify, fix, and improve handling of `[query]` and `{{QUERY}}` placeholders.
### Added
None.
### Changed
- Updated the query placeholder detection and substitution logic for `[query]` and `{{QUERY}}` strings in `backend/open_webui/utils/task.py`.
### Deprecated
None.
### Removed
None.
### Fixed
- Fixed logic errors in query placeholder escaping and unintended replacement of context values in `backend/open_webui/utils/task.py`.
### Security
None.
### Breaking Changes
None.
---
### Additional Information
This PR addresses & fixes #19101.
Updated prompts were manually tested and verified using a proxy OpenAI-compatible proxy API to inspect system & user messages.
LLM Chat Query prompt with changes from this PR:
`````
Messages since the last assistant response:
- user
```
### Task:
Respond to the user query using the provided context, incorporating inline citations in the format [id] **only when the <source> tag includes an explicit id attribute** (e.g., <source id="1">).
### Guidelines:
- If you don't know the answer, clearly state that.
- If uncertain, ask the user for clarification.
- Respond in the same language as the user's query.
- If the context is unreadable or of poor quality, inform the user and provide the best possible answer.
- If the answer isn't present in the context but you possess the knowledge, explain this to the user and provide the answer using your own understanding.
- **Only include inline citations using [id] (e.g., [1], [2]) when the <source> tag includes an id attribute.**
- Do not cite if the <source> tag does not contain an id attribute.
- Do not use XML tags in your response.
- Ensure citations are concise and directly related to the information provided.
### Example of Citation:
If the user asks about a specific topic and the information is found in a source with a provided id attribute, the response should include the citation like in the following example:
* "According to the study, the proposed method increases efficiency by 20% [1]."
### Output:
Provide a clear and direct response to the user's query, including inline citations in the format [id] only when the <source> tag with id attribute is present in the context.
<context>
<source id="1" name="test/get_current_time">{{QUERY}} [query] Current Date and Time = Tuesday, November 11, 2025, 02:02:37 AM</source>
</context>
<user_query>
what time is it?
</user_query>
what time is it?
Tool `test/get_current_time` Output: {{QUERY}} [query] Current Date and Time = Tuesday, November 11, 2025, 02:02:37 AM
```
`````
This PR specifically addresses the code responsible for the escaping faulty logic:
https://github.com/open-webui/open-webui/blob/e0d5de16978786b8a7538adf1efcde5258f38faf/backend/open_webui/utils/task.py#L207-L224
### Screenshots or Videos
None.
### Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/19102
Author: @matiboux
Created: 11/11/2025
Status: ❌ Closed
Base:
dev← Head:fix/rag-template-query-placeholder📝 Commits (1)
d009c9bFix template query placeholder escaping logic📊 Changes
1 file changed (+6 additions, -10 deletions)
View changed files
📝
backend/open_webui/utils/task.py(+6 -10)📄 Description
Pull Request Checklist
Before submitting, make sure you've checked the following:
devbranch. Not targeting thedevbranch will lead to immediate closure of the PR.Changelog Entry
Description
rag_templatefunction withinbackend/open_webui/utils/task.pyto simplify, fix, and improve handling of[query]and{{QUERY}}placeholders.Added
None.
Changed
[query]and{{QUERY}}strings inbackend/open_webui/utils/task.py.Deprecated
None.
Removed
None.
Fixed
backend/open_webui/utils/task.py.Security
None.
Breaking Changes
None.
Additional Information
This PR addresses & fixes #19101.
Updated prompts were manually tested and verified using a proxy OpenAI-compatible proxy API to inspect system & user messages.
LLM Chat Query prompt with changes from this PR:
This PR specifically addresses the code responsible for the escaping faulty logic:
https://github.com/open-webui/open-webui/blob/e0d5de16978786b8a7538adf1efcde5258f38faf/backend/open_webui/utils/task.py#L207-L224
Screenshots or Videos
None.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.