Chat requests sometimes need a small transformation before reaching a model. An Open WebUI filter function can add a prefix to the latest user message while keeping its activation limited to one private model.

Functions are managed from Admin Panel → Functions. Open WebUI recognizes a class Filter definition, and its inlet() method receives the chat request body before the provider processes it. Returning the modified body passes the change onward without rewriting the message displayed in chat.

An administrator account, an existing private text-chat model, and access to the provider's request trace are needed. Function code runs with the Open WebUI server's permissions, so a harmless text marker is a suitable first test; the marker does not establish that a message has passed a moderation check.

Steps to create a filter function in Open WebUI:

  1. Open the user menu.

  2. Select Admin Panel.
  3. Open Functions.
  4. Click Create.
  5. Enter Message Prefix Filter in Function Name.

    The editor generates message_prefix_filter as the Function ID. IDs must be valid Python identifiers.

  6. Enter Prefix the latest text user message with [reviewed]. in Function Description.
  7. Replace the starter source with this metadata block.
    """
    title: Message Prefix Filter
    author: Open WebUI admin
    version: 0.1
    """
     
    from typing import Optional

    The metadata identifies the function; Optional describes the optional user argument used by the inlet.

  8. Append the Filter class below the import.
    class Filter:
        def __init__(self):
            self.name = "Message Prefix Filter"

    The class name identifies a filter rather than a tool or pipe.

  9. Add the inlet method inside Filter at the same indentation as __init__.
        async def inlet(
            self, body: dict, __user__: Optional[dict] = None
        ) -> dict:
            for message in reversed(body.get("messages", [])):
                if message.get("role") == "user":
                    content = message.get("content")
                    if isinstance(content, str):
                        message["content"] = f"[reviewed] {content}"
                    break
            return body

    The reverse search finds the latest user message. The text check preserves structured image content, and break prevents changes to older messages. The inlet returns the request body whether or not it adds the prefix.

    Saving a function can execute Python with access to server files, environment variables, and network services. Untrusted imports or prompt logging can expose credentials and conversations. This source only changes text in memory and installs no dependencies.

  10. Click Save & Create.

    The confirmation acknowledges arbitrary code execution and trust in the source. An unexpected source change is a reason to cancel.

  11. Click Confirm to save the reviewed function.

    The confirmation reports Function created successfully.

  12. Enable the switch at the right of the Message Prefix Filter row.

  13. Open the function's three-dot menu.

    Global must remain off so that other models do not inherit this filter. If a later test fails, disabling the function's row switch stops its execution without deleting the source.

  14. Press Escape to close the function menu.

  15. Open the user menu.

  16. Select Settings.
  17. Select Models under Admin → AI.

    These are headings within Settings. The private models here are company-chat and company-chat-alt; only the first receives the filter.

  18. Open the existing company-chat model.
  19. Open Filters.
  20. Select Message Prefix Filter.
  21. Click Done to close the filter picker.
  22. Click Save & Update.
  23. Click Back at the top left of Settings.
  24. Open New Chat from the sidebar.
  25. Open the model picker beside the message composer.
  26. Select company-chat.
  27. Enter the test question in the composer.
    What is 2 + 2?

  28. Click the send arrow.
  29. Check the reply from company-chat.

    The answer proves the model still responds, but it does not prove the exact text the provider received.

  30. Inspect the latest user message in the provider's request trace.
    [reviewed] What is 2 + 2?

    The trace must show the added prefix before the original question. A model-generated echo or the unmodified browser request to Open WebUI cannot establish this server-side change. Request-body tracing should be limited to synthetic prompts because real conversations may contain private data.

  31. Open another New Chat.
  32. Open the model picker.
  33. Select the unbound company-chat-alt model.
  34. Enter the test question in the composer.
    What is 2 + 2?

  35. Click the send arrow.
  36. Check the reply from company-chat-alt.
  37. Verify the control model's provider request contains the original question without the prefix.
    What is 2 + 2?

    The filtered model remains bound to Message Prefix Filter, while the control model's request stays unchanged.

Share this guide