Valves
Valves
Valves and UserValves are used to allow users to provide dynamic details such as an API key or a configuration option. These will create a fillable field or a bool switch in the GUI menu for the given function. They are always optional, but HIGHLY encouraged.
Hence, Valves and UserValves class can be defined in either a Pipe, Pipeline, Filter or Tools class.
Valves are configurable by admins alone via the Tools or Functions menus. On the other hand UserValves are configurable by any users directly from a chat session.
Commented example
Input Types
Valves support special input types that change how fields are rendered in the UI. You can configure these using json_schema_extra with the input key in your Pydantic Field definitions.
Password Input (Masked Fields)
For sensitive fields like passwords, API keys, or secrets, you can use the password input type to mask the value in the UI. This prevents the password from being visible on screen (protecting against shoulder surfing).
from pydantic import BaseModel, Field
class Tools:
class UserValves(BaseModel):
service_password: str = Field(
default="",
description="Your service password",
json_schema_extra={"input": {"type": "password"}}
)
When rendered, this field will appear as a masked input (dots instead of characters) with a toggle to reveal the value if needed, using Open WebUI's SensitiveInput component.
Use password input types for any credential or secret that users configure in their Valves or UserValves. This is especially important for UserValves since they are configurable by end users directly from the chat interface.
Select Dropdown Input
For fields where users should choose from a predefined list of options, use the select input type to render a dropdown menu. Options can be either static (hardcoded list) or dynamic (generated at runtime by a method).
Static Options
Use a list directly for options that don't change:
from pydantic import BaseModel, Field
class Tools:
class Valves(BaseModel):
priority: str = Field(
default="medium",
description="Processing priority level",
json_schema_extra={
"input": {
"type": "select",
"options": ["low", "medium", "high"]
}
}
)
You can also use label/value pairs for more descriptive options:
from pydantic import BaseModel, Field
class Tools:
class Valves(BaseModel):
log_level: str = Field(
default="info",
description="Logging verbosity",
json_schema_extra={
"input": {
"type": "select",
"options": [
{"value": "debug", "label": "Debug (Verbose)"},
{"value": "info", "label": "Info (Standard)"},
{"value": "warn", "label": "Warning (Minimal)"},
{"value": "error", "label": "Error (Critical Only)"}
]
}
}
)
Dynamic Options
For options that need to be generated at runtime (e.g., fetching available models, databases, or user-specific resources), specify a method name as a string. The method will be called when the configuration UI is rendered:
from pydantic import BaseModel, Field
class Tools:
class Valves(BaseModel):
selected_model: str = Field(
default="",
description="Choose a model to use",
json_schema_extra={
"input": {
"type": "select",
"options": "get_model_options" # Method name as string
}
}
)
@classmethod
def get_model_options(cls, __user__=None) -> list[dict]:
"""
Dynamically fetch available models.
Called when the Valves configuration UI is opened.
"""
# Example: Return options based on runtime state
return [
{"value": "gpt-4", "label": "GPT-4"},
{"value": "gpt-3.5-turbo", "label": "GPT-3.5 Turbo"},
{"value": "claude-3-opus", "label": "Claude 3 Opus"}
]
The method can accept an optional __user__ parameter to generate user-specific options:
from pydantic import BaseModel, Field
class Tools:
class UserValves(BaseModel):
workspace: str = Field(
default="",
description="Select your workspace",
json_schema_extra={
"input": {
"type": "select",
"options": "get_user_workspaces"
}
}
)
@classmethod
def get_user_workspaces(cls, __user__=None) -> list[dict]:
"""
Return workspaces available to the current user.
__user__ contains the user's information as a dict.
"""
if not __user__:
return []
user_id = __user__.get("id")
# Fetch user-specific workspaces from your data source
return [
{"value": "ws-1", "label": "Personal Workspace"},
{"value": "ws-2", "label": "Team Workspace"}
]
Dynamic options are particularly useful for:
- Fetching available API models from connected providers
- Loading database or file options based on current system state
- Presenting user-specific resources like projects or workspaces
- Any scenario where options change based on runtime context