85a0b2e Fix memory context injection when system prompt is empty
📊 Changes
1 file changed (+13 additions, -3 deletions)
View changed files
📝backend/open_webui/utils/middleware.py (+13 -3)
📄 Description
Summary
Skip memory-context system-message injection when no system prompt is configured.
Prevent empty `User Context:
` system messages from being appended.
Why
When the system prompt is intentionally blank, middleware still appended a system message via memory handling. This caused unintended prompt injection and unnecessary context artifacts.
Changes
In chat_memory_handler (backend/open_webui/utils/middleware.py):
Return early if current system prompt is blank.
Append User Context only when memory query produced non-empty context.
Testing
✅ I personally tested the change locally.
✅ Verified no User Context system message is appended when system prompt is empty.
✅ Verified User Context is appended when system prompt is set and memory returns results.
🔄 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/21583
**Author:** [@lesj0610](https://github.com/lesj0610)
**Created:** 2/19/2026
**Status:** ❌ Closed
**Base:** `main` ← **Head:** `fix/memory-context-system-prompt-gate`
---
### 📝 Commits (1)
- [`85a0b2e`](https://github.com/open-webui/open-webui/commit/85a0b2eaa050b559cd1b70f34344cc4efaaf5d1c) Fix memory context injection when system prompt is empty
### 📊 Changes
**1 file changed** (+13 additions, -3 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/utils/middleware.py` (+13 -3)
</details>
### 📄 Description
## Summary
- Skip memory-context system-message injection when no system prompt is configured.
- Prevent empty `User Context:
` system messages from being appended.
## Why
When the system prompt is intentionally blank, middleware still appended a system message via memory handling. This caused unintended prompt injection and unnecessary context artifacts.
## Changes
- In `chat_memory_handler` (`backend/open_webui/utils/middleware.py`):
- Return early if current system prompt is blank.
- Append `User Context` only when memory query produced non-empty context.
## Testing
- ✅ I personally tested the change locally.
- ✅ Verified no `User Context` system message is appended when system prompt is empty.
- ✅ Verified `User Context` is appended when system prompt is set and memory returns results.
- ✅ `python3 -m compileall backend/open_webui/utils/middleware.py`
contributor license agreement
---
<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/21583
Author: @lesj0610
Created: 2/19/2026
Status: ❌ Closed
Base:
main← Head:fix/memory-context-system-prompt-gate📝 Commits (1)
85a0b2eFix memory context injection when system prompt is empty📊 Changes
1 file changed (+13 additions, -3 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+13 -3)📄 Description
Summary
` system messages from being appended.
Why
When the system prompt is intentionally blank, middleware still appended a system message via memory handling. This caused unintended prompt injection and unnecessary context artifacts.
Changes
chat_memory_handler(backend/open_webui/utils/middleware.py):User Contextonly when memory query produced non-empty context.Testing
User Contextsystem message is appended when system prompt is empty.User Contextis appended when system prompt is set and memory returns results.python3 -m compileall backend/open_webui/utils/middleware.pycontributor license agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.