LibreChat

Message Filter Object Structure

Overview

The messageFilter object configures server-side message filters. In v1.3.13, the supported filter type is messageFilter.pii.

messageFilter.pii rejects submitted message text that matches credential-shaped starter patterns or operator-defined regular expressions before the text reaches moderation, a model request, or message persistence.

Example

messageFilter:
  pii:
    starterPatterns:
      - sk_prefix
      - bearer_header
      - api_key_header
    customPatterns:
      - id: anthropic_api_key
        label: Anthropic API key
        regex: 'sk-ant-[A-Za-z0-9_-]{20,}'

Fields

messageFilter.pii

KeyTypeDescriptionExample
pii.starterPatternsArray of StringsOptional subset of built-in starter pattern ids to enable. Omit to enable all starter patterns.starterPatterns: [sk_prefix, bearer_header]
pii.customPatternsArray of ObjectsOperator-defined patterns. Each entry requires `id`, `label`, and `regex`.

Built-in starter pattern ids:

  • sk_prefix: matches sk- style token prefixes.
  • bearer_header: matches bearer tokens in text.
  • api_key_header: matches api-key header-shaped text.

customPatterns

KeyTypeDescriptionExample
idStringStable pattern id used for logs and debugging.id: anthropic_api_key
labelStringHuman-readable label shown in the rejection message.label: Anthropic API key
regexStringJavaScript-flavor regular expression. LibreChat validates it at config load time and compiles it with the global flag.regex: 'sk-ant-[A-Za-z0-9_-]{20,}'

Behavior

When submitted message text matches a configured PII pattern, LibreChat returns HTTP 400 with message_filter_pii_block and a message asking the caller to remove the matched credential type.

The filter checks:

  • Chat route user text submitted through the LibreChat UI.
  • Text content across all caller-supplied message roles in OpenAI-compatible Chat Completions requests.
  • Text content across all caller-supplied message roles in OpenAI-compatible Responses requests.

The filter evaluates text supplied in the request body. It does not scan file contents.

How is this guide?