{"record":{"id":"0fa1395cf98939c1","repo":"BerriAI/litellm","slug":"guardrail-failed-n-violation-s-detected-0fa139","errorCode":null,"errorMessage":"Guardrail failed: {n} violation(s) detected","messagePattern":"Guardrail failed: (.+?) violation\\(s\\) detected","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/enkryptai/enkryptai.py","lineNumber":310,"sourceCode":"        if _messages:\n            for message in _messages:\n                _content = message.get(\"content\")\n                if isinstance(_content, str):\n                    result = await self._call_enkryptai_guardrails(\n                        prompt=_content,\n                        request_data=data,\n                    )\n\n                    verbose_proxy_logger.debug(\"Guardrails async_pre_call_hook result: %s\", result)\n\n                    # Process the guardrails response\n                    processed_result = self._process_enkryptai_guardrails_response(result)\n                    attacks_detected = processed_result[\"attacks_detected\"]\n\n                    # If any attacks are detected, raise an error\n                    if attacks_detected:\n                        error_message = self._create_error_message(processed_result)\n                        raise ValueError(error_message)\n\n        # Add guardrail to applied guardrails header\n        add_guardrail_to_applied_guardrails_header(request_data=data, guardrail_name=self.guardrail_name)\n\n        return data\n\n    async def async_moderation_hook(\n        self,\n        data: dict,\n        user_api_key_dict: UserAPIKeyAuth,\n        call_type: CallTypesLiteral,\n    ):\n        \"\"\"\n        Runs in parallel to LLM API call\n        Runs on only Input\n\n        This can NOT modify the input, only used to reject or accept a call before going to LLM API\n        \"\"\"","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/enkryptai/enkryptai.py#L292-L328","documentation":"ValueError raised in EnkryptAIGuardrail.async_pre_call_hook when _process_enkryptai_guardrails_response finds attacks_detected for the scanned prompt text. EnkryptAI's /guardrails/policy/detect endpoint flags prompt attacks (jailbreaks, prompt injection); the error message enumerates the detected attack types. The proxy maps this to an HTTP 400 before the LLM call is made.","triggerScenarios":"A chat completion on a model with the enkryptai guardrail where mode includes pre_call, the policy_name policy is evaluated, and the detect response flags at least one attack vector in the user's messages.","commonSituations":"Red-team or security-testing prompts; benign prompts that resemble injection patterns (instructions about ignoring rules, quoted system prompts); a policy_name tuned too aggressively after being copied between environments.","solutions":["Read the attack types listed in the error message body to see what was detected.","Retune the EnkryptAI policy referenced by policy_name in the EnkryptAI dashboard.","Verify policy_name actually points at the intended policy — an empty/wrong name can evaluate the account default.","Restrict the hook scope with mode (drop pre_call) or remove the guardrail from models that legitimately receive instruction-heavy prompts."],"exampleFix":"# before\nlitellm_params:\n  guardrail: enkryptai\n  mode: pre_call\n  policy_name: strict-injection\n\n# after\nlitellm_params:\n  guardrail: enkryptai\n  mode: pre_call\n  policy_name: balanced-injection","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"def is_enkryptai_violation(exc: BaseException) -> bool:\n    return isinstance(exc, ValueError) and 'violation(s) detected' in str(exc)","tryCatchPattern":"from litellm.exceptions import BadRequestError\ntry:\n    resp = client.chat.completions.create(model=model, messages=msgs)\nexcept BadRequestError as e:\n    if 'violation(s) detected' in str(e):\n        return {'error': 'prompt_flagged', 'detail': str(e)}, 400\n    raise","preventionTips":["Verify policy_name exists and matches the intended policy before rollout.","Run a labeled corpus of legitimate prompts through detection to measure false positives.","Keep injection policies scoped to untrusted-input routes only."],"tags":["enkryptai","guardrail","prompt-injection","pre-call","content-moderation"],"backgroundTag":"guardrail-policy-violation","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}