BerriAI/litellm · error · ValueError
Guardrail failed: {n} violation(s) detected
Error message
Guardrail failed: {n} violation(s) detected What it means
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.
Source
Thrown at litellm/proxy/guardrails/guardrail_hooks/enkryptai/enkryptai.py:310
if _messages:
for message in _messages:
_content = message.get("content")
if isinstance(_content, str):
result = await self._call_enkryptai_guardrails(
prompt=_content,
request_data=data,
)
verbose_proxy_logger.debug("Guardrails async_pre_call_hook result: %s", result)
# Process the guardrails response
processed_result = self._process_enkryptai_guardrails_response(result)
attacks_detected = processed_result["attacks_detected"]
# If any attacks are detected, raise an error
if attacks_detected:
error_message = self._create_error_message(processed_result)
raise ValueError(error_message)
# Add guardrail to applied guardrails header
add_guardrail_to_applied_guardrails_header(request_data=data, guardrail_name=self.guardrail_name)
return data
async def async_moderation_hook(
self,
data: dict,
user_api_key_dict: UserAPIKeyAuth,
call_type: CallTypesLiteral,
):
"""
Runs in parallel to LLM API call
Runs on only Input
This can NOT modify the input, only used to reject or accept a call before going to LLM API
"""View on GitHub (pinned to 77b7c6c40c)
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.
Example fix
# before litellm_params: guardrail: enkryptai mode: pre_call policy_name: strict-injection # after litellm_params: guardrail: enkryptai mode: pre_call policy_name: balanced-injection
Defensive patterns
Strategy: try-catch
Type guard
def is_enkryptai_violation(exc: BaseException) -> bool:
return isinstance(exc, ValueError) and 'violation(s) detected' in str(exc) Try / catch
from litellm.exceptions import BadRequestError
try:
resp = client.chat.completions.create(model=model, messages=msgs)
except BadRequestError as e:
if 'violation(s) detected' in str(e):
return {'error': 'prompt_flagged', 'detail': str(e)}, 400
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Guardrail failed: {n} violation(s) detected
- {blocked.explanation}
- {refusal}
- Content violates policy
- EnkryptAI API key is required. Set ENKRYPTAI_API_KEY environ
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/0fa1395cf98939c1.
Report an issue: GitHub.