{"record":{"id":"36a4162bfb9feb50","repo":"BerriAI/litellm","slug":"litellm-params-mode-is-required-e-g-pre-call-po","errorCode":null,"errorMessage":"litellm_params.mode is required (e.g. pre_call, post_call)","messagePattern":"litellm_params\\.mode is required \\(e\\.g\\. pre_call, post_call\\)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_endpoints.py","lineNumber":747,"sourceCode":"    if not api_base:\n        raise HTTPException(\n            status_code=400,\n            detail=\"litellm_params.api_base is required for generic_guardrail_api\",\n        )\n    parsed: Final = urlparse(api_base)\n    if parsed.scheme not in (\"http\", \"https\"):\n        raise HTTPException(\n            status_code=400,\n            detail=\"litellm_params.api_base must use http or https scheme\",\n        )\n    if not parsed.hostname:\n        raise HTTPException(\n            status_code=400,\n            detail=\"litellm_params.api_base must contain a valid hostname\",\n        )\n    mode: Final = params.get(\"mode\")\n    if mode is None:\n        raise HTTPException(\n            status_code=400,\n            detail=\"litellm_params.mode is required (e.g. pre_call, post_call)\",\n        )\n\n    try:\n        existing = await _guardrails_table(prisma_client).find_unique(where={\"guardrail_name\": request.guardrail_name})\n        if existing is not None:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Guardrail with name {request.guardrail_name!r} already exists\",\n            )\n    except HTTPException:\n        raise\n    except Exception as e:\n        verbose_proxy_logger.exception(\"Error checking guardrail name uniqueness: %s\", e)\n        raise HTTPException(status_code=500, detail=str(e))\n\n    now: Final = datetime.now(timezone.utc)","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_endpoints.py#L729-L765","documentation":"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.","triggerScenarios":"Thrown at litellm/proxy/guardrails/guardrail_endpoints.py:747 when the library encounters an invalid state.","commonSituations":"The guardrail config omitted the mode field.","solutions":["Set litellm_params.mode (e.g. pre_call, post_call) on the guardrail."],"exampleFix":"litellm_params:\n  mode: pre_call","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}