BerriAI/litellm · error · HTTPException
litellm_params.mode is required (e.g. pre_call, post_call)
Error message
litellm_params.mode is required (e.g. pre_call, post_call)
What it means
Raised in the generic-guardrail registration handler when litellm_params contains no 'mode' entry. The mode determines when the guardrail hook fires (pre_call, post_call, during_call, etc.); a registration without it cannot be scheduled into the hook pipeline, so the request is rejected with HTTP 400 at registration time.
Source
Thrown at litellm/proxy/guardrails/guardrail_endpoints.py:747
if not api_base:
raise HTTPException(
status_code=400,
detail="litellm_params.api_base is required for generic_guardrail_api",
)
parsed: Final = urlparse(api_base)
if parsed.scheme not in ("http", "https"):
raise HTTPException(
status_code=400,
detail="litellm_params.api_base must use http or https scheme",
)
if not parsed.hostname:
raise HTTPException(
status_code=400,
detail="litellm_params.api_base must contain a valid hostname",
)
mode: Final = params.get("mode")
if mode is None:
raise HTTPException(
status_code=400,
detail="litellm_params.mode is required (e.g. pre_call, post_call)",
)
try:
existing = await _guardrails_table(prisma_client).find_unique(where={"guardrail_name": request.guardrail_name})
if existing is not None:
raise HTTPException(
status_code=400,
detail=f"Guardrail with name {request.guardrail_name!r} already exists",
)
except HTTPException:
raise
except Exception as e:
verbose_proxy_logger.exception("Error checking guardrail name uniqueness: %s", e)
raise HTTPException(status_code=500, detail=str(e))
now: Final = datetime.now(timezone.utc)View on GitHub (pinned to 77b7c6c40c)
Solutions
- Set litellm_params.mode (e.g. pre_call, post_call) on the guardrail.
Example fix
litellm_params: mode: pre_call
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/proxy/guardrails/guardrail_endpoints.py:747 when the library encounters an invalid state.
Common situations: The guardrail config omitted the mode field.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/36a4162bfb9feb50.
Report an issue: GitHub.