When the LiteLLM content filter is enough to screen sensitive data
Your self-hosted LiteLLM gateway forwards prompts to model providers, and the team needs to stop card numbers, internal identifiers or banned terms before they leave your environment. The LiteLLM content filter is a local regex and keyword guardrail with BLOCK and MASK actions and no external API calls, so screening happens inside the gateway you already run. It is a good fit when the sensitive data has a recognizable shape, such as a payment card number, a national or employee identifier that follows a fixed format, or a short list of project code names or competitor names that must never reach a provider. Because nothing is sent to a third-party service, it also suits teams whose data handling rules do not allow a screening call to leave the network.
The filter works on patterns and exact terms, so its boundary is set by what those patterns can express. Prebuilt patterns and custom regular expressions catch values that look a certain way, but they cannot judge meaning. A customer complaint that describes a person's medical history in plain sentences, or an internal document that paraphrases a confidential strategy, will pass a keyword list. Before you rely on it, confirm with your data owners which categories of sensitive data appear in real prompts, sample those prompts, and measure what the patterns miss. Where unstructured personal data or context-dependent content is a material risk, plan a separate ML-based detector or a dedicated DLP control and keep the content filter as a fast first layer.
What the filter detects: prebuilt patterns, custom regex and keywords
The LiteLLM content filter runs three local detection methods, each with BLOCK and MASK actions and no external API calls. They differ in what they catch well and in how much your team must keep current, so the choice of method per data type matters more than the filter as a whole.
Prebuilt regex patterns
Prebuilt patterns ship with the filter and cover common structured identifiers, so you can start screening without writing expressions. They suit well-formed data such as card numbers and other standard formats. Confirm the exact prebuilt pattern list against the LiteLLM content filter docs for your version before you rely on it, because the list changes between releases. Test each pattern on samples from your own data, since a generic pattern can miss internal formats or flag harmless numbers.
Content filter docsCustom regex patterns
Custom regex covers identifiers the prebuilt set does not know, such as internal employee numbers, customer reference formats or project codes. Your team owns every expression, so each one needs a named owner, test cases with both matching and non-matching inputs, and a review when the format changes. Poorly bounded expressions can match too broadly and mask ordinary text, or match too narrowly and let identifiers through. Keep the patterns in version control alongside the gateway configuration.
Banned keyword matching
Keyword matching blocks exact terms such as internal code names, unreleased product names or restricted project labels. It is simple to read and audit, but it matches only the terms you list, so variants, abbreviations and misspellings pass unless you add them. Decide whether each keyword should block the whole request or mask the term, and document that choice. Review the list on a set schedule with the teams that own the sensitive terms.
Maintenance and false positives
Every method needs ongoing tuning, and the maintenance burden grows with the number of patterns and teams. Track blocked and masked events in your logs, sample them regularly, and adjust patterns that generate false positives for legitimate workflows. Assign the work to a named owner, and agree how changes move through review before they reach production keys. Ask the vendor or your own test results to confirm how the filter handles text that combines several detection types in one request.
Configuration options and when each fits
This table compares the main choices for the built-in content filter: the BLOCK and MASK actions, prebuilt patterns, custom regex, and banned keyword lists. Read each row for the situation it suits and the trade-off it carries, then confirm the exact settings against the current LiteLLM content filter documentation before you configure anything.
| Option | When it fits | Trade-off | Where it applies |
|---|---|---|---|
| BLOCK action | Card numbers or identifiers that must never reach a model provider, such as regulated data with a clear rejection policy | The request stops and the caller gets an error, so applications need to handle the refusal and users may retry | Input screening before the model call, and output screening if your setup checks responses |
| MASK action | Traffic where the request should still succeed and the sensitive value only needs to be hidden from the provider | The model receives altered text, which can change answers or break formatting in downstream code | Input or output, applied per key, team or model where the guardrail is attached |
| Prebuilt patterns | Common formats such as payment card numbers and standard identifiers, when you want a starting set without writing expressions | Coverage is limited to what the built-in set detects, so test false positives and misses against your own data | Any scope the guardrail is attached to, after confirming the pattern list in the docs |
| Custom regex | Internal identifiers such as employee, case or account number formats that prebuilt patterns do not cover | Expressions need careful testing, since overly broad rules block or mask legitimate text and gaps go unnoticed | Any scope the guardrail is attached to, with test cases kept under version control |
| Banned keyword list | Project code names, unreleased product names or terms that must never be sent to a provider | Exact matching misses variants, spelling changes and paraphrases, so it is not a substitute for classification | Input or output, with ownership of the list assigned to a named team |
| Per key or team scope | Different teams need different strictness, such as a finance group needing BLOCK while a research group uses MASK | Each scope adds configuration to review and retest, and scope mistakes can leave traffic unscreened | Virtual keys and teams, which depend on the access model you set up |
| Streaming responses | Output screening where users receive model text as it is generated and you need checks to run during the stream | Partial text may reach the user before a match is found, so confirm how the filter handles chunks in your version | Output during streaming, which should be verified in a test environment first |
| Need for an ML-based detector | Free-form personal data, context-dependent secrets or names that patterns cannot express reliably | Adds a separate service or model to run, with its own latency, cost and data handling to review | Use alongside the built-in filter when pattern coverage is not enough for your data |
How a prompt moves through the filter before the model call
The request starts at the client, which sends an OpenAI-format call to the LiteLLM proxy. Inside the gateway, the content filter checks the text against prebuilt patterns, custom regex and banned keywords. Each match is handled by one of two actions: BLOCK returns an error to the caller, and MASK replaces the matched text before forwarding. Clean requests pass through unchanged to the model provider. The whole check runs inside the gateway with no external API call, so confirm which rules and actions you need before testing.
Filter runs inside the gateway, with no external service call.
How streaming responses and the filter interact
For a standard request that returns one complete response, the filter can work on the full text at each point it runs. On the input side, it inspects the messages before they leave the gateway, so a matching card number or banned keyword can be masked or the request blocked before any provider receives it. This is the most predictable case, because the filter sees the whole prompt and the whole answer in one piece.
- Input screening: the messages are checked before the provider call, and a BLOCK match returns an error to the caller instead of forwarding the request.
- Output screening: the complete response body is available, so matches can be masked before it is returned to the application.
- Masked values: the replacement text is applied to the whole string, so the caller receives one consistent, redacted response.
- Logging: confirm whether the original or the masked text is written to request logs, since the log may hold the sensitive value even when the caller does not.
- Error shape: confirm how a blocked request is reported to the client so your application can handle it.
Before relying on this path, send test prompts containing each pattern type you care about and confirm the masked output, the block response and the log entries in your own environment.
A streamed response arrives as many small chunks, and a sensitive value can be split across two chunks, for example a card number whose first half ends one chunk and whose second half starts the next. A pattern that matches a complete string may not match either fragment on its own. Masking a stream is therefore not the same as masking a finished response: the gateway has to decide what to hold back, what to release and how to handle a match that spans chunk boundaries.
- Stated feature, not a guarantee: streaming support is listed for the filter, but confirm it for the endpoints, providers and LiteLLM version you run.
- Boundary matches: test a value deliberately split across chunks and check whether it is detected and masked.
- Already-sent text: once a chunk reaches the client, it cannot be recalled, so output screening on a stream may only prevent later content from leaving.
- Blocking mid-stream: confirm what the client receives when a block fires partway through a response.
- Client behavior: check that your SDKs and front ends handle an interrupted or altered stream without crashing.
The safest approach is to test streamed and non-streamed calls with the same prompts and compare the results side by side.
Screening before the model call protects the provider from receiving sensitive input, which is usually the main concern for data leaving your environment. Screening after the call only examines what the model generated, which can catch data the model repeats or produces, but it cannot stop the prompt from having already been sent. The two checks answer different questions, and a control set should state which one it relies on.
- Pre-call protects inputs: a masked or blocked prompt never reaches the provider, which is the stronger control for personal data in user prompts.
- Post-call protects outputs: it catches sensitive values that appear in model answers, including ones the model invents or reproduces from context.
- Cost of each point: output checks add work after the model responds, and their effect on latency depends on how the gateway is configured, so measure it.
- Tool and retrieved content: text that enters from documents or tool results may bypass a check that only looks at the user message, so confirm which fields are scanned.
- Documented placement: check the guardrail mode settings for each point before assuming a rule runs where you expect.
Write down which point each control covers and test each one separately before accepting it as part of your data-handling design.
Before depending on output screening, run a short test plan in an environment that matches production as closely as possible, using the same LiteLLM version, provider, endpoint and client library. Synthetic values are enough for this, and they keep real personal data out of test logs. Record each result so the evidence can be reused in a review.
- Endpoint matrix: cover the chat completions endpoint and any other endpoint your applications use, in both streaming and non-streaming mode.
- Split-value cases: place patterns across chunk boundaries and confirm each outcome.
- Output-only leakage: ask prompts that cause the model to repeat or produce matching values and confirm they are masked or blocked.
- Log review: check that logs, traces and metrics do not keep unmasked values where they should not.
- Upgrade regression: repeat the tests after each LiteLLM upgrade, since streaming behavior can change between releases.
Ask your implementation partner or the LiteLLM maintainers to confirm streaming support for each endpoint and version you plan to use, and do not treat the feature list alone as proof.
Setting up the content filter on a self-hosted gateway
This sequence takes a self-hosted LiteLLM gateway from a confirmed release line to a content filter that blocks or masks the sensitive data categories your organization has defined, with evidence that it behaves as intended on both chat and other endpoints.
Confirm the LiteLLM version and release line
Check which LiteLLM release your gateway runs and compare it with the current entries on the LiteLLM releases page. Confirm the content filter guardrail and its configuration keys exist in your version by reading the release notes and the content filter documentation for that release. Record the exact image tag in your change record. Done when the running version, its release line and the guardrail's presence in that version are written down and the team agrees the release is one LiteLLM still supports.
Define sensitive data categories and owners
Your security, privacy and business owners list the data types the filter must catch, such as payment card numbers, national identifiers, internal project codes and banned keywords. For each category, name an owner who approves the pattern, the action and any exceptions. Keep the list short enough that every entry has a test sample. Done when you have a signed category register with one owner per entry and a sample of known-bad and known-good text for each.
Add the content filter guardrail to the gateway configuration
Add a guardrail entry to the gateway configuration file that uses the LiteLLM content filter, referencing the prebuilt patterns you need and your custom regex and keyword lists. Store the configuration as code in your repository and deploy it through your normal change process. Keep the filter fully local, since it makes no external API calls. Done when the gateway starts without configuration errors and the guardrail appears as loaded in the proxy logs or admin view.
Choose BLOCK or MASK for each category
For each category in the register, decide whether a match should stop the request (BLOCK) or replace the matched text before it reaches the model (MASK). Blocking suits categories where any occurrence is unacceptable, while masking suits identifiers that users may paste inadvertently and that the model does not need. Record the decision and its owner next to each category. Done when every category has exactly one action in the configuration and the decision record matches the configuration file.
Scope the filter to teams or keys where needed
If not every team should be screened in the same way, attach the guardrail only to the teams, virtual keys or models that need it, using the scoping options in your LiteLLM version. Confirm which options your edition supports, because some team-level guardrail controls belong to LiteLLM Enterprise. Done when a key outside the scope sends a sample card-like string without a block or mask, and a key inside the scope triggers the configured action.
Test with known-bad and known-good samples
Send each sample from the register through the gateway's chat completions endpoint and through the other endpoints your teams use, such as embeddings or responses, using the test keys for each scope. Check that BLOCK categories return an error to the caller and that MASK categories reach the model with replaced text. Include known-good text that resembles a match, such as order numbers, to measure false positives. Done when every sample produces the expected result on every endpoint, and the logs show the guardrail action for each test.
Confirm streaming behavior and record the gaps
Repeat the critical tests with streaming responses enabled, since the content filter supports streaming and you need to see how a match is handled mid-stream in your version. Record any category where a match is detected too late, and decide whether that category needs an external detector. Document the categories the regex filter cannot reliably identify, such as free-text names or context-dependent data, and note where an ML-based detector is still needed. Done when the test report lists the streaming results, the false positive rate observed in your samples, and a written list of residual gaps signed off by the category owners.
Security and operational considerations
A content filter is only as safe as the logs it writes, the secrets that protect the gateway and the rules that change over time. The cards below cover the controls to set before the filter goes live, and the checks to repeat after every rule change.
Logs of matched content
Find out where the gateway writes matched text, request payloads and guardrail events, and who can read them. A masked prompt can still leave the original value in request logs, debug output or spend records if logging captures the request before masking runs. Test with a planted test card number, then search every log sink, database table and trace store for that value. Confirm the behavior with the LiteLLM logging documentation for your version before relying on it.
Content filter docsMasked values in storage
Decide whether logs should store the original sensitive value, a masked version or nothing at all. Retention periods and access rights for those logs matter as much as the filter itself, because a log store is often less controlled than the model call. Set a short retention for raw request content, restrict read access to a small group, and document the decision so compliance reviewers can trace it.
- Spend batch interval
- 60 seconds
Master key and config in a secret manager
Store LITELLM_MASTER_KEY and the proxy configuration file outside the container image and the Git repository. The master key must start with sk-, and anyone holding it can administer keys and guardrails. Use a secret manager with access logging, rotate the key on a planned schedule, and confirm that guardrail definitions are loaded from the protected configuration rather than from editable settings.
Change control for regex rules
Treat every custom regex and keyword list as code. Keep rules in version control, require a reviewer for each change, and run a fixed set of test inputs (including valid card-like numbers, near misses and clean text) before a rule reaches production. Record who approved each change and the reason, so a missed leak can be traced to a specific rule revision.
Regex denial of service
Patterns with nested quantifiers or overlapping alternatives can take far longer on crafted input than on normal text, which slows or stalls the gateway for every team. Avoid nested repetition, keep patterns anchored and bounded, and test each rule against long, adversarial strings before release. Set limits on request size at the gateway, and watch latency metrics after each rule change.
Scope of the built-in checks
Confirm what the filter does not cover before you rely on it: prebuilt patterns match formats, not meaning, so names, addresses and free-text health details will pass through. Document which data classes the filter handles and which need a detector, and check the rule set against a sample of real prompts from each team with the owners' permission. Review coverage each time a new model or endpoint is added.
Where an ML-based detector is still needed
Pattern matching covers structured identifiers well and free-form personal data poorly. The built-in filter is strong where the sensitive value has a recognizable shape, such as a card number, an account format or a fixed keyword. It is weak where the sensitive value is just language: a person's name, a home address written in prose, a diagnosis described in a support chat, a salary or debt figure mentioned in passing, or an identifier that only means something in context, such as a case number that looks like any other number. Multilingual input adds another gap, because patterns and keywords written for one language and one set of formats will miss the same data written in another. Before relying on the filter for personal data, the team should sample real prompts from the teams that will use the gateway and count what the patterns miss, not what they catch.
An ML-based detector is a second layer, not a replacement. A self-hosted named-entity or PII model, or an external guardrail service, can run alongside the built-in filter at the same gateway. The usual arrangement is to keep the deterministic regex and keyword rules first, since they are fast and their behavior is easy to explain to an auditor, and to add the detector only for the categories the rules cannot reach. Each added call adds a dependency, latency and a data path that must be reviewed. Confirm where the detector runs, whether prompt text leaves your network, what it does on timeout and whether its results can be logged without storing the sensitive value itself. The sibling topics on guardrail modes, the Microsoft Purview, Google Model Armor and Prisma AIRS integrations, and secret redaction cover how those options attach to the request.
Decide the categories first, then choose the tool. List the data classes your policy treats as sensitive, mark which ones have a recognizable format and which depend on meaning, and assign the built-in filter to the first group and a detector to the second. Test both layers together with a fixed set of synthetic prompts that includes names, addresses, multilingual text and streamed responses. Ask any detector vendor or project to show its accuracy on your languages and your document types, and plan a review cadence, because a detector that passes today's test set may drift as your prompts change. Whether your organization needs these controls to meet a specific privacy or security obligation is a question for your compliance team and assessor.
Questions buyers ask before using the LiteLLM content filter
Does the LiteLLM content filter need an external service?
No. LiteLLM's content filter runs on the gateway itself, using prebuilt regex patterns, custom regex and keyword matching, with BLOCK and MASK actions and no external API calls. Your gateway host and its configuration are the only places the matching happens, which keeps the check inside infrastructure you control. Confirm this against the version you plan to run, because guardrail options change between releases. Read the LiteLLM content filter documentation before you finalize the design, and test a sample prompt in a non-production environment to confirm the action taken on each pattern.
What work does a content filter setup need from our team?
Your team needs to define what counts as sensitive, and someone has to own the decision for each pattern. The work usually breaks into four parts: listing the data types to catch (card numbers, national identifiers, internal project codes, banned terms), choosing BLOCK or MASK for each, writing and testing any custom regex, and reviewing matches with the teams whose prompts will be affected. Security or privacy staff should sign off on the rules, and platform engineers should own the configuration, usually kept in version control. Expect the rules to need tuning after the first weeks of traffic, since false positives on legitimate text are the most common early complaint.
How long does a content filter rollout take?
Duration depends mostly on how many data types you must cover and how many teams and models the rules apply to. A filter with a few prebuilt patterns on one team's traffic is a much smaller job than a multi-team policy with custom regex, streaming responses and staged rollout. No duration figures are supplied for this topic, so ask any implementation partner for a timeline built from your written scope, and confirm the milestones: rule design, test corpus, staging run, production enablement and tuning. Fixed-scope engagements are agreed in writing before work starts, so the timeline should be part of that written scope.
Can our own team set up the LiteLLM content filter alone?
A team that already runs the LiteLLM proxy, manages its configuration as code and has someone comfortable with regular expressions can usually set up basic BLOCK and MASK rules in-house. The harder parts are building a realistic test set of prompts, measuring false positives and false negatives, and documenting the rules well enough for a compliance review. If your team lacks one of these skills, or the filter must be evidenced to auditors, a partner can take on that portion within a fixed scope. Before deciding, check whether your team has the gateway admin access, a staging environment and time allocated for tuning.
What makes the content filter effort go up?
Effort rises with the number of patterns, the amount of custom regex, and the variety of traffic the filter must inspect. The main drivers are:
- Custom identifiers that have no prebuilt pattern and need careful regex design and testing
- Multiple teams, keys or models that need different actions, which adds policy and test work
- Streaming responses, where masking and blocking behave differently from complete responses and need their own verification
- Tuning cycles driven by false positives in production prompts
- Evidence requirements from security reviews or privacy assessments, which add documentation work
Reduce effort by limiting the scope to the data types that matter most and by reusing a tested rule set across teams.
Does the LiteLLM content filter meet a privacy or compliance requirement?
No. A content filter is one control among others. It can reduce the chance that certain sensitive values reach a model provider, but it does not make your gateway compliant with a privacy law, a payment standard or an industry framework on its own. Whether the control satisfies a requirement is decided by your legal, privacy and compliance teams and by the independent auditor or certification body that reviews your environment. DeployOpen can prepare systems, controls and evidence for a compliance assessment, but it does not issue audit reports, attestations or certifications. Ask your assessor early which evidence they expect, such as the rule definitions, test results and change records.
When is an ML-based detector still needed alongside the content filter?
A regex and keyword filter works well for structured data with predictable formats, such as card numbers or identifiers with check digits. It struggles with free-form personal information, names, addresses, context-dependent secrets and paraphrased sensitive content, where a pattern match will miss real cases or flag harmless text. In those cases you may need an ML-based or external detector in addition to the built-in filter. Before adding one, confirm where that detector sends data, since an external service changes your data-flow review. Test both layers against the same sample set so you can see which gaps each one covers.
Does the filter cover streaming responses too?
Support for streaming needs to be confirmed for your LiteLLM version before you rely on it. Streaming responses arrive in pieces, so a pattern such as a card number can split across chunks and be missed if the filter only sees whole messages. Check the LiteLLM content filter documentation for the streaming behavior of the release you run, then test with split values, long responses and multiple chunk sizes. Also decide what happens when a block fires mid-stream, since the caller may already have received part of the response.
How DeployOpen scopes and delivers content filter rollouts
DeployOpen plans and deploys LiteLLM's built-in content filter inside the infrastructure you control, with patterns, actions and routing tied to your data classes and approved models. Each engagement is fixed-scope, with the filter rules, test cases and handover documents agreed in writing before the build starts.
How we scope
- We inventory which identifiers, card numbers and banned terms your teams send through the gateway, and which models and keys receive them.
- The written scope names the prebuilt patterns, custom regex and keyword lists to enable, plus the BLOCK or MASK action for each.
- We confirm where streaming responses pass through the proxy, since output screening depends on how your callers consume the stream.
How we build
- We configure the guardrail in your LiteLLM config as code, with the regex and keyword rules kept in version control.
- We test each pattern against sample inputs that include true positives, near misses and false positives, and record the results.
- We document where a local pattern match stops being enough, so you can decide whether an ML-based detector belongs in the design.
How we hand over
- You receive the configuration, the rule inventory, the test cases and the results from our verification runs.
- Operating notes cover how to add or change a pattern, how to review blocked and masked events in your logs and who approves changes.
- Your team runs a walkthrough of the rollout so the people who own the gateway can maintain the rules after handover.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer, including re-testing rules after LiteLLM upgrades.
- Support can cover updating patterns when new data types appear in your traffic and re-running the test set against them.
- Confirm with your team the retainer scope, response expectations and who can request changes before the engagement begins.

