mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #18639] [CLOSED] feat(prompts): add support for prompts as prompt variables #63717
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?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/18639
Author: @Davixk
Created: 10/26/2025
Status: ❌ Closed
Base:
dev← Head:feat/prompts-as-variables📝 Commits (3)
8cb2f85feat(prompts): add support for prompt variable substitution1cf5250refactor(prompts): add recursive prompt variable resolutiondee3db4feat(prompts): add prompt reference validation on save📊 Changes
9 files changed (+520 additions, -35 deletions)
View changed files
📝
backend/open_webui/functions.py(+3 -1)📝
backend/open_webui/routers/ollama.py(+6 -2)📝
backend/open_webui/routers/openai.py(+3 -1)📝
backend/open_webui/routers/prompts.py(+98 -1)📝
backend/open_webui/utils/middleware.py(+13 -4)📝
backend/open_webui/utils/payload.py(+47 -3)📝
backend/open_webui/utils/task.py(+280 -15)📝
src/lib/apis/prompts/index.ts(+32 -0)📝
src/lib/components/workspace/Prompts/PromptEditor.svelte(+38 -8)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch. Not targeting thedevbranch may lead to immediate closure of the PR.Changelog Entry
Description
This PR introduces a powerful new feature that combines workspace prompts with prompt variables, allowing users to reference workspace prompts using
{{PROMPTS.prompt_name}}syntax within model system prompts and other contexts. The feature includes intelligent access control that respects user permissions while providing elevated access for admin-owned models, ensuring security without sacrificing functionality.Added
{{PROMPTS.prompt_name}}variable syntax that allows referencing workspace prompts by their command name{{CURRENT_DATETIME}},{{USER_NAME}}, etc.) are automatically resolvedtask.py:_get_user_variables(): Extracts user information into a dictionary for template processing_resolve_basic_variables(): Handles resolution of date/time and user-related variablesreplace_prompts_variable(): Core function for{{PROMPTS.*}}substitution with recursion preventionChanged
apply_system_prompt_to_body()inpayload.pyto accept optionalmodelparameter for ownership checksapply_system_prompt_to_body()to fetch appropriate prompts based on model ownership (all prompts for admin-owned models, accessible prompts for others)apply_system_prompt_to_body()in:middleware.py(2 locations)openai.py(1 location)ollama.py(2 locations)functions.py(1 location)Deprecated
Removed
Fixed
Promptsfromtask.pySecurity
Breaking Changes
Additional Information
Use Cases
Example Usage
Create a workspace prompt with command
expert-persona:Reference it in a model's system prompt:
The final resolved prompt will include the expert persona content with all variables expanded.
Technical Implementation Details
{{PROMPTS.*}}references within referenced prompts are intentionally not resolved to prevent complexity and potential circular dependenciesuser_idbelongs to a user withrole == "admin"Screenshots or Videos
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.