litellm - 💡(How to fix) Fix Custom redaction tags (keyword_redaction_tag, pattern_redaction_format) not working in v1.87.1 [3 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

Possible Root Cause

Fix Action

Fixed

Code Example

keyword_redaction_tag: "***REDACTED***"
pattern_redaction_format: "***{pattern_name}***"

---

curl -X POST "http://10.200.9.249:30090/guardrails" \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{
    "guardrail": {
      "guardrail_name": "custom-tag-test",
      "litellm_params": {
        "guardrail": "litellm_content_filter",
        "mode": "pre_call",
        "default_on": true,
        "keyword_redaction_tag": "***REDACTED***",
        "blocked_words": [{"keyword": "test", "action": "MASK"}]
      }
    }
  }'

# Test call
curl -X POST "http://10.200.9.249:30090/v1/chat/completions" \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model":"Qwen3-0.6B","messages":[{"role":"user","content":"this is test"}]}'

---

curl -X POST "http://10.200.9.249:30090/guardrails" \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{
    "guardrail": {
      "guardrail_name": "custom-pattern-test",
      "litellm_params": {
        "guardrail": "litellm_content_filter",
        "mode": "pre_call",
        "default_on": true,
        "pattern_redaction_format": "***{pattern_name}***",
        "patterns": [{"pattern_type": "regex", "pattern": "1[3-9]\\d{9}", "name": "PHONE", "action": "MASK"}]
      }
    }
  }'

# Test call
curl -X POST "http://10.200.9.249:30090/v1/chat/completions" \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model":"Qwen3-0.6B","messages":[{"role":"user","content":"phone 13800138000"}]}'

---

# Line 206-209
self.pattern_redaction_format = (
    pattern_redaction_format or self.PATTERN_REDACTION_FORMAT
)
self.keyword_redaction_tag = keyword_redaction_tag or self.KEYWORD_REDACTION_STR
RAW_BUFFERClick to expand / collapse

Bug Description

Custom redaction tags (keyword_redaction_tag and pattern_redaction_format) configuration parameters are not working as documented in v1.87.1.

According to the official documentation, these parameters should allow customizing the placeholder format for redacted content.

Expected Behavior

When configured with:

keyword_redaction_tag: "***REDACTED***"
pattern_redaction_format: "***{pattern_name}***"

Redacted content should use the custom placeholders.

Actual Behavior

Configuration can be saved to database, but runtime does not read these values. Placeholders are fixed to default values:

  • Keywords → [KEYWORD_REDACTED]
  • Patterns → [{pattern_name}_REDACTED]

Test Evidence

Test 1: Custom keyword_redaction_tag

curl -X POST "http://10.200.9.249:30090/guardrails" \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{
    "guardrail": {
      "guardrail_name": "custom-tag-test",
      "litellm_params": {
        "guardrail": "litellm_content_filter",
        "mode": "pre_call",
        "default_on": true,
        "keyword_redaction_tag": "***REDACTED***",
        "blocked_words": [{"keyword": "test", "action": "MASK"}]
      }
    }
  }'

# Test call
curl -X POST "http://10.200.9.249:30090/v1/chat/completions" \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model":"Qwen3-0.6B","messages":[{"role":"user","content":"this is test"}]}'

Expected: this is ***REDACTED***
Actual: this is [KEYWORD_REDACTED]

Test 2: Custom pattern_redaction_format

curl -X POST "http://10.200.9.249:30090/guardrails" \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{
    "guardrail": {
      "guardrail_name": "custom-pattern-test",
      "litellm_params": {
        "guardrail": "litellm_content_filter",
        "mode": "pre_call",
        "default_on": true,
        "pattern_redaction_format": "***{pattern_name}***",
        "patterns": [{"pattern_type": "regex", "pattern": "1[3-9]\\d{9}", "name": "PHONE", "action": "MASK"}]
      }
    }
  }'

# Test call
curl -X POST "http://10.200.9.249:30090/v1/chat/completions" \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model":"Qwen3-0.6B","messages":[{"role":"user","content":"phone 13800138000"}]}'

Expected: phone ***PHONE***
Actual: phone [PHONE_REDACTED]

Code Analysis

The code in content_filter.py shows correct implementation:

# Line 206-209
self.pattern_redaction_format = (
    pattern_redaction_format or self.PATTERN_REDACTION_FORMAT
)
self.keyword_redaction_tag = keyword_redaction_tag or self.KEYWORD_REDACTION_STR

However, the parameters may not be correctly passed from the configuration layer to the guardrail initialization.

Environment

  • LiteLLM Version: v1.87.1
  • Deployment: Proxy mode
  • Configuration: Via /guardrails API endpoint
  • Test Date: 2026-06-05

Possible Root Cause

The configuration is saved to the database but may not be properly loaded when initializing the ContentFilterGuardrail instance. The parameters might be missing in the deserialization/instantiation path.

Request

Could you please:

  1. Confirm if this is a known issue
  2. Check if the fix is already in v1.88.x or later versions
  3. Provide guidance on proper configuration if we're using it incorrectly

Thank you!

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING