[PR #4487] [MERGED] Custom Default System Prompt #4642

Closed
opened 2026-02-22 18:36:14 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/4487
Author: @angelplusultra
Created: 10/3/2025
Status: Merged
Merged: 11/24/2025
Merged by: @timothycarambat

Base: masterHead: 3906-global-default-system-prompt


📝 Commits (6)

  • 9a68012 Add Default System Prompt Management
  • 72d7a9f Remove validation for system prompt in ChatSettings component
  • 8ed4ebe Add comment for system prompt in workspaces model
  • a5f7a56 merge master
  • 134c17b linting, simplify logic for default assumption
  • 0181be1 dev build

📊 Changes

15 files changed (+477 additions, -69 deletions)

View changed files

📝 .github/workflows/dev-build.yaml (+1 -1)
📝 frontend/src/App.jsx (+7 -0)
📝 frontend/src/components/SettingsSidebar/index.jsx (+6 -0)
📝 frontend/src/models/system.js (+33 -0)
frontend/src/pages/Admin/DefaultSystemPrompt/index.jsx (+270 -0)
📝 frontend/src/pages/WorkspaceSettings/ChatSettings/ChatPromptSettings/index.jsx (+72 -55)
📝 frontend/src/pages/WorkspaceSettings/ChatSettings/index.jsx (+6 -3)
📝 frontend/src/utils/chat/index.js (+1 -1)
📝 frontend/src/utils/paths.js (+3 -0)
📝 server/endpoints/system.js (+51 -0)
📝 server/models/systemSettings.js (+10 -0)
📝 server/models/workspace.js (+10 -2)
📝 server/prisma/schema.prisma (+1 -0)
📝 server/utils/chats/index.js (+2 -2)
📝 server/utils/helpers/chat/convertTo.js (+4 -5)

📄 Description

Pull Request Type

  • feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

Relevant Issues

resolves #3906

What is in this change?

This PR introduces a new Custom Default System Prompt feature that allows administrators to define a global default system prompt that will be automatically applied to all newly created workspaces. This provides a centralized way to standardize AI behavior across your AnythingLLM instance without needing to configure each workspace individually.

How It Works

Backend Implementation

  • A new default_system_prompt setting is stored in the system_settings table
  • When a new workspace is created (Workspace.new()), the system checks for a custom default system prompt
  • If a custom prompt is configured, it's applied to the new workspace's openAiPrompt field
  • If no custom prompt is set, the workspace uses the "sane default" system prompt:
    Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed.
    

API Endpoints

Two new endpoints have been added to /system:

  1. GET /system/default-system-prompt

    • Returns the current default system prompt and the sane default
    • Available to all authenticated users in multi-user mode
    • Response includes:
      • defaultSystemPrompt: The custom prompt (or sane default if not set)
      • saneDefaultSystemPrompt: The built-in default for reference
  2. POST /system/default-system-prompt

    • Updates the default system prompt
    • Admin-only in multi-user mode
    • Accepts defaultSystemPrompt in request body
    • Returns success/failure message

Multi-User Mode Permissions

Who Can See This Feature?

In multi-user mode, access is role-based:

  • Admins: Full access - can view and modify the default system prompt
  • Managers: Read-only - can fetch the default prompt but cannot modify it
  • Default Users: Read-only - can fetch the default prompt but cannot modify it

The settings page in the UI is only visible to admins through the navigation menu at:
Settings → Admin → Default System Prompt

Single-User Mode

In single-user mode, the feature is available without restrictions since there is no authentication.

How to Set Your Own Custom Default System Prompt

Step 1: Navigate to the Settings Page

  1. Log in as an admin user
  2. Click on the Settings button (gear icon)
  3. In the sidebar, expand the Admin section
  4. Click on Default System Prompt

Step 2: Configure Your Custom Prompt

  1. Click into the System Prompt text area to begin editing
  2. Enter your desired default system prompt
  3. The prompt will be highlighted with any system prompt variables you use (e.g., {date}, {time}, {user.name})
  4. Click Save Changes when finished

Step 3: Supported Variables

You can enhance your system prompt with dynamic variables:

  • System variables: {time}, {date}, {datetime}
  • User variables (multi-user mode only): {user.id}, {user.name}, {user.bio}
  • Custom variables: Create your own at Settings → Tools → System Prompt Variables

Click on the system prompt variables link on the settings page to see all available variables.

Example Custom Prompt

You are a helpful AI assistant for our company. Today's date is {date} and the time is {time}.
You are chatting with {user.name}. Always be professional, concise, and accurate in your responses.
When providing code examples, use markdown formatting. If you're unsure about something, say so.

How to Restore to the Sane Default

  1. Navigate to Settings → Admin → Default System Prompt
  2. Clear the entire text field (delete all text)
  3. Click Save Changes
  4. The system will automatically use the sane default for all new workspaces
  5. The text area will display the sane default prompt for reference

Important Notes

Scope of Changes

  • Only affects NEW workspaces created after setting the custom prompt
  • Does NOT modify existing workspaces automatically
  • Each workspace can still override its prompt in Workspace Settings → Chat Settings

Workspace-Specific Customization

Even after setting a global default, individual workspaces can be customized:

  1. Navigate to the specific workspace
  2. Click Settings (gear icon)
  3. Go to Chat Settings
  4. Click "Restore to Default" to use the global default, or customize further

Use Cases

This feature is particularly useful for:

  • Standardizing AI behavior across your organization
  • Enforcing company policies in AI responses (e.g., tone, formatting, disclaimers)
  • Reducing setup time when creating multiple workspaces
  • Maintaining consistency in multi-tenant or multi-team environments
  • Injecting dynamic context like current date/time or user information

Technical Details

Database Schema

The custom prompt is stored in the system_settings table:

  • Label: default_system_prompt
  • Value: The custom prompt text (or NULL if using sane default)

Code Changes

Backend:

  • server/endpoints/system.js: New GET/POST endpoints
  • server/models/systemSettings.js: Added saneDefaultSystemPrompt constant and default_system_prompt to supportedFields
  • server/models/workspace.js: Modified new() method to check for custom default prompt

Frontend:

  • frontend/src/pages/Admin/DefaultSystemPrompt/index.jsx: New settings page
  • frontend/src/models/system.js: New API methods fetchDefaultSystemPrompt() and updateDefaultSystemPrompt()
  • frontend/src/components/SettingsSidebar/index.jsx: Added menu item for admins
  • frontend/src/pages/WorkspaceSettings/ChatSettings/ChatPromptSettings/index.jsx: Added "Restore to Default" functionality

Additional Information

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 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/Mintplex-Labs/anything-llm/pull/4487 **Author:** [@angelplusultra](https://github.com/angelplusultra) **Created:** 10/3/2025 **Status:** ✅ Merged **Merged:** 11/24/2025 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `3906-global-default-system-prompt` --- ### 📝 Commits (6) - [`9a68012`](https://github.com/Mintplex-Labs/anything-llm/commit/9a680128a940016d4a7795883209e9f495508ef2) Add Default System Prompt Management - [`72d7a9f`](https://github.com/Mintplex-Labs/anything-llm/commit/72d7a9f176150f5e141d3e96f4dca8d2c8f9c461) Remove validation for system prompt in ChatSettings component - [`8ed4ebe`](https://github.com/Mintplex-Labs/anything-llm/commit/8ed4ebefc6a7a6007863e505f8284ae38b1a4248) Add comment for system prompt in workspaces model - [`a5f7a56`](https://github.com/Mintplex-Labs/anything-llm/commit/a5f7a56eaa3ebf31e05825f3cd95a4ddd425cfa9) merge master - [`134c17b`](https://github.com/Mintplex-Labs/anything-llm/commit/134c17be3aa1b7971061454d4801325ae463b0eb) linting, simplify logic for default assumption - [`0181be1`](https://github.com/Mintplex-Labs/anything-llm/commit/0181be1706dad17a85e28661ef51cbef993e3d4f) dev build ### 📊 Changes **15 files changed** (+477 additions, -69 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/dev-build.yaml` (+1 -1) 📝 `frontend/src/App.jsx` (+7 -0) 📝 `frontend/src/components/SettingsSidebar/index.jsx` (+6 -0) 📝 `frontend/src/models/system.js` (+33 -0) ➕ `frontend/src/pages/Admin/DefaultSystemPrompt/index.jsx` (+270 -0) 📝 `frontend/src/pages/WorkspaceSettings/ChatSettings/ChatPromptSettings/index.jsx` (+72 -55) 📝 `frontend/src/pages/WorkspaceSettings/ChatSettings/index.jsx` (+6 -3) 📝 `frontend/src/utils/chat/index.js` (+1 -1) 📝 `frontend/src/utils/paths.js` (+3 -0) 📝 `server/endpoints/system.js` (+51 -0) 📝 `server/models/systemSettings.js` (+10 -0) 📝 `server/models/workspace.js` (+10 -2) 📝 `server/prisma/schema.prisma` (+1 -0) 📝 `server/utils/chats/index.js` (+2 -2) 📝 `server/utils/helpers/chat/convertTo.js` (+4 -5) </details> ### 📄 Description ### Pull Request Type <!-- For change type, change [ ] to [x]. --> - [x] ✨ feat - [ ] 🐛 fix - [ ] ♻️ refactor - [ ] 💄 style - [ ] 🔨 chore - [ ] 📝 docs ### Relevant Issues <!-- Use "resolves #xxx" to auto resolve on merge. Otherwise, please use "connect #xxx" --> resolves #3906 ### What is in this change? <!-- Describe the changes in this PR that are impactful to the repo. --> This PR introduces a new **Custom Default System Prompt** feature that allows administrators to define a global default system prompt that will be automatically applied to all newly created workspaces. This provides a centralized way to standardize AI behavior across your AnythingLLM instance without needing to configure each workspace individually. ## How It Works ### Backend Implementation - A new `default_system_prompt` setting is stored in the `system_settings` table - When a new workspace is created (`Workspace.new()`), the system checks for a custom default system prompt - If a custom prompt is configured, it's applied to the new workspace's `openAiPrompt` field - If no custom prompt is set, the workspace uses the "sane default" system prompt: ``` Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed. ``` ### API Endpoints Two new endpoints have been added to `/system`: 1. **GET `/system/default-system-prompt`** - Returns the current default system prompt and the sane default - Available to **all authenticated users** in multi-user mode - Response includes: - `defaultSystemPrompt`: The custom prompt (or sane default if not set) - `saneDefaultSystemPrompt`: The built-in default for reference 2. **POST `/system/default-system-prompt`** - Updates the default system prompt - **Admin-only** in multi-user mode - Accepts `defaultSystemPrompt` in request body - Returns success/failure message ## Multi-User Mode Permissions ### Who Can See This Feature? In multi-user mode, access is role-based: - **Admins**: Full access - can view and modify the default system prompt - **Managers**: Read-only - can fetch the default prompt but cannot modify it - **Default Users**: Read-only - can fetch the default prompt but cannot modify it The settings page in the UI is only visible to **admins** through the navigation menu at: **Settings → Admin → Default System Prompt** ### Single-User Mode In single-user mode, the feature is available without restrictions since there is no authentication. ## How to Set Your Own Custom Default System Prompt ### Step 1: Navigate to the Settings Page 1. Log in as an **admin** user 2. Click on the **Settings** button (gear icon) 3. In the sidebar, expand the **Admin** section 4. Click on **Default System Prompt** ### Step 2: Configure Your Custom Prompt 1. Click into the **System Prompt** text area to begin editing 2. Enter your desired default system prompt 3. The prompt will be highlighted with any system prompt variables you use (e.g., `{date}`, `{time}`, `{user.name}`) 4. Click **Save Changes** when finished ### Step 3: Supported Variables You can enhance your system prompt with dynamic variables: - **System variables**: `{time}`, `{date}`, `{datetime}` - **User variables** (multi-user mode only): `{user.id}`, `{user.name}`, `{user.bio}` - **Custom variables**: Create your own at Settings → Tools → System Prompt Variables Click on the *system prompt variables* link on the settings page to see all available variables. ### Example Custom Prompt ``` You are a helpful AI assistant for our company. Today's date is {date} and the time is {time}. You are chatting with {user.name}. Always be professional, concise, and accurate in your responses. When providing code examples, use markdown formatting. If you're unsure about something, say so. ``` ## How to Restore to the Sane Default 1. Navigate to **Settings → Admin → Default System Prompt** 2. **Clear the entire text field** (delete all text) 3. Click **Save Changes** 4. The system will automatically use the sane default for all new workspaces 5. The text area will display the sane default prompt for reference ## Important Notes ### Scope of Changes - ✅ **Only affects NEW workspaces** created after setting the custom prompt - ❌ **Does NOT modify existing workspaces** automatically - ✅ Each workspace can still override its prompt in **Workspace Settings → Chat Settings** ### Workspace-Specific Customization Even after setting a global default, individual workspaces can be customized: 1. Navigate to the specific workspace 2. Click **Settings** (gear icon) 3. Go to **Chat Settings** 4. Click "Restore to Default" to use the global default, or customize further ### Use Cases This feature is particularly useful for: - **Standardizing AI behavior** across your organization - **Enforcing company policies** in AI responses (e.g., tone, formatting, disclaimers) - **Reducing setup time** when creating multiple workspaces - **Maintaining consistency** in multi-tenant or multi-team environments - **Injecting dynamic context** like current date/time or user information ## Technical Details ### Database Schema The custom prompt is stored in the `system_settings` table: - **Label**: `default_system_prompt` - **Value**: The custom prompt text (or NULL if using sane default) ### Code Changes **Backend:** - `server/endpoints/system.js`: New GET/POST endpoints - `server/models/systemSettings.js`: Added `saneDefaultSystemPrompt` constant and `default_system_prompt` to `supportedFields` - `server/models/workspace.js`: Modified `new()` method to check for custom default prompt **Frontend:** - `frontend/src/pages/Admin/DefaultSystemPrompt/index.jsx`: New settings page - `frontend/src/models/system.js`: New API methods `fetchDefaultSystemPrompt()` and `updateDefaultSystemPrompt()` - `frontend/src/components/SettingsSidebar/index.jsx`: Added menu item for admins - `frontend/src/pages/WorkspaceSettings/ChatSettings/ChatPromptSettings/index.jsx`: Added "Restore to Default" functionality --- ### Additional Information <!-- Add any other context about the Pull Request here that was not captured above. --> ### Developer Validations <!-- All of the applicable items should be checked. --> - [x] I ran `yarn lint` from the root of the repo & committed changes - [x] Relevant documentation has been updated - [x] I have tested my code functionality - [ ] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-22 18:36:14 -05:00
yindo closed this issue 2026-02-22 18:36:15 -05:00
yindo changed title from [PR #4487] Custom Default System Prompt to [PR #4487] [MERGED] Custom Default System Prompt 2026-06-05 15:19:36 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#4642