{"record":{"id":"772d9ce010c35547","repo":"BerriAI/litellm","slug":"keyword-banned-keyword-word","errorCode":null,"errorMessage":"Keyword banned. Keyword={word}","messagePattern":"Keyword banned\\. Keyword=(.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"enterprise/enterprise_hooks/banned_keywords.py","lineNumber":62,"sourceCode":"                )\n            except Exception as e:\n                raise Exception(\n                    f\"An error occurred: {str(e)}, banned_keywords_list={banned_keywords_list}\"\n                )\n\n    def print_verbose(self, print_statement, level: Literal[\"INFO\", \"DEBUG\"] = \"DEBUG\"):\n        if level == \"INFO\":\n            verbose_proxy_logger.info(print_statement)\n        elif level == \"DEBUG\":\n            verbose_proxy_logger.debug(print_statement)\n\n        if litellm.set_verbose is True:\n            print(print_statement)  # noqa\n\n    def test_violation(self, test_str: str):\n        for word in self.banned_keywords_list:\n            if word in test_str.lower():\n                raise HTTPException(\n                    status_code=400,\n                    detail={\"error\": f\"Keyword banned. Keyword={word}\"},\n                )\n\n    async def async_pre_call_hook(\n        self,\n        user_api_key_dict: UserAPIKeyAuth,\n        cache: DualCache,\n        data: dict,\n        call_type: str,  # \"completion\", \"embeddings\", \"image_generation\", \"moderation\"\n    ):\n        try:\n            \"\"\"\n            - check if user id part of call\n            - check if user id part of blocked list\n            \"\"\"\n            self.print_verbose(\"Inside Banned Keyword List Pre-Call Hook\")\n            if is_text_content_call_type(call_type):","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/enterprise_hooks/banned_keywords.py#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from fastapi import HTTPException\n\ntry:\n    resp = client.chat.completions.create(model=\"gpt-4o\", messages=msgs, user=\"u1\")\nexcept HTTPException as e:\n    if e.status_code == 400 and \"Keyword banned\" in str(e.detail):\n        # content-policy rejection: surface to the end user, do not retry\n        raise UserContentViolation(e.detail[\"error\"]) from e\n    raise","preventionTips":["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."],"tags":["enterprise","banned-keywords","content-filter","http-400","pre-call-hook"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}