diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index cc5f57e0c3..d80066e1dd 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -2265,7 +2265,8 @@ def sanitize_tool_pairs(messages: list[dict]) -> list[dict]: return sanitized -SKILL_MENTION_RE = re.compile(r'<(?:\$([^|>]+)(?:\|[^>]*)?|/([^|>]+)\|[^>]*)>') +# Ids are validated as [a-z0-9_-]+ on create; matching that keeps ordinary "<$..." text intact. +SKILL_MENTION_RE = re.compile(r'<(?:\$([a-z0-9_-]+)(?:\|[^>]*)?|/([a-z0-9_-]+)\|[^>]*)>') def _get_text_parts(message: dict) -> list[str]: @@ -2287,7 +2288,7 @@ def extract_skill_ids_from_messages(messages: list[dict]) -> set[str]: return ids -SKILL_MENTION_STRIP_RE = re.compile(r'<(?:\$[^|>]+(?:\|([^>]*))?|/[^|>]+\|([^>]*))>') +SKILL_MENTION_STRIP_RE = re.compile(r'<(?:\$[a-z0-9_-]+(?:\|([^>]*))?|/[a-z0-9_-]+\|([^>]*))>') def strip_skill_mentions(messages: list[dict]) -> None: