BerriAI/litellm · warning · HTTPException
Keyword banned. Keyword={word}
Error message
Keyword banned. Keyword={word} What it means
Raised as an HTTPException (400) by the BannedKeywords enterprise hook when a request's text (prompt, messages, etc., lowercased) contains any substring from banned_keywords_list. It is an intentional content-policy rejection, not a malfunction. The offending keyword is echoed back in the detail payload.
Source
Thrown at enterprise/enterprise_hooks/banned_keywords.py:62
)
except Exception as e:
raise Exception(
f"An error occurred: {str(e)}, banned_keywords_list={banned_keywords_list}"
)
def print_verbose(self, print_statement, level: Literal["INFO", "DEBUG"] = "DEBUG"):
if level == "INFO":
verbose_proxy_logger.info(print_statement)
elif level == "DEBUG":
verbose_proxy_logger.debug(print_statement)
if litellm.set_verbose is True:
print(print_statement) # noqa
def test_violation(self, test_str: str):
for word in self.banned_keywords_list:
if word in test_str.lower():
raise HTTPException(
status_code=400,
detail={"error": f"Keyword banned. Keyword={word}"},
)
async def async_pre_call_hook(
self,
user_api_key_dict: UserAPIKeyAuth,
cache: DualCache,
data: dict,
call_type: str, # "completion", "embeddings", "image_generation", "moderation"
):
try:
"""
- check if user id part of call
- check if user id part of blocked list
"""
self.print_verbose("Inside Banned Keyword List Pre-Call Hook")
if is_text_content_call_type(call_type):View on GitHub (pinned to 6c2dcb801b)
Solutions
- Remove or rephrase the offending keyword occurrence in the request payload.
- If this is a false positive, ask the proxy admin to remove or replace the keyword in banned_keywords_list.
- Admins: prefer word-boundary matching or more specific keywords to avoid substring false positives.
- Admins: check the proxy logs (print_verbose DEBUG output) to see which keyword matched.
Defensive patterns
Strategy: try-catch
Try / catch
from fastapi import HTTPException
try:
resp = client.chat.completions.create(model="gpt-4o", messages=msgs, user="u1")
except HTTPException as e:
if e.status_code == 400 and "Keyword banned" in str(e.detail):
# content-policy rejection: surface to the end user, do not retry
raise UserContentViolation(e.detail["error"]) from e
raise Prevention
- Client-side: scan outbound prompts against the same keyword list before sending.
- Admin: use specific keywords, not substrings that match innocent words.
- Treat 400 keyword rejections as terminal — retries with identical payload always fail.
- Log which keyword matched (from the error detail) to guide prompt edits.
When it happens
Trigger: Any /chat/completions, /embeddings, or similar call routed through async_pre_call_hook where test_violation finds a banned word as a substring of the lowercased input text. Because matching is naive substring containment, a banned word also triggers when it appears inside a larger word.
Common situations: Users legitimately hitting a content filter configured by their organization; false positives from substring matching (e.g. banning 'assassin' but the text contains 'sassassin' style overlaps, or banned words appearing in code/logs being sent to the LLM).
Related errors
- User blocked from making LLM API Calls. User={user}
- Violated content safety policy. Category={category}
- Violated content safety policy
- Violated content safety policy
- Violated content safety policy
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/772d9ce010c35547.
Report an issue: GitHub.