{"record":{"id":"ad03e78c5f54d219","repo":"BerriAI/litellm","slug":"guardrail-type-is-required","errorCode":null,"errorMessage":"guardrail_type is required","messagePattern":"guardrail_type is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_registry.py","lineNumber":478,"sourceCode":"        if isinstance(litellm_params_data, dict):\n            litellm_params = LitellmParams(**litellm_params_data)\n        else:\n            litellm_params = litellm_params_data\n\n        if \"category_thresholds\" in litellm_params_data and litellm_params_data[\"category_thresholds\"]:\n            lakera_category_thresholds: Final = LakeraCategoryThresholds(**litellm_params_data[\"category_thresholds\"])\n            litellm_params.category_thresholds = lakera_category_thresholds\n\n        if litellm_params.api_key and litellm_params.api_key.startswith(\"os.environ/\"):\n            litellm_params.api_key = str(get_secret(litellm_params.api_key))\n\n        if litellm_params.api_base and litellm_params.api_base.startswith(\"os.environ/\"):\n            litellm_params.api_base = str(get_secret(litellm_params.api_base))\n\n        guardrail_type: Final = litellm_params.guardrail\n\n        if guardrail_type is None:\n            raise ValueError(\"guardrail_type is required\")\n\n        initializer: Final = guardrail_initializer_registry.get(guardrail_type)\n\n        if initializer:\n            # Try to call with llm_router first, fall back to without if it fails\n            import inspect\n\n            sig: Final = inspect.signature(initializer)\n            if \"llm_router\" in sig.parameters:\n                custom_guardrail_callback = initializer(\n                    litellm_params,\n                    guardrail,\n                    llm_router,\n                )\n            else:\n                custom_guardrail_callback = initializer(litellm_params, guardrail)\n        elif isinstance(guardrail_type, str) and \".\" in guardrail_type:\n            custom_guardrail_callback = self.initialize_custom_guardrail(","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_registry.py#L460-L496","documentation":"When initializing a guardrail, litellm reads the guardrail type from litellm_params.guardrail and looks it up in the initializer registry. If that key is absent or None, no initializer can be selected and ValueError('guardrail_type is required') is raised at proxy startup or guardrail creation time.","triggerScenarios":"A guardrails config entry whose litellm_params block is missing the guardrail key (e.g. only mode/default_on set), or a /guardrails/create API call whose litellm_params omits it.","commonSituations":"YAML indentation mistake putting guardrail at the entry top level instead of under litellm_params; hand-written config missing the type key; guardrail created programmatically without the field.","solutions":["Add guardrail: <type> (e.g. aim, bedrock, hide_secrets) inside litellm_params","Check YAML indentation - keys like guardrail, mode, api_key must sit under litellm_params","Validate the guardrails block against litellm's documented config schema before restarting"],"exampleFix":"# before\nguardrails:\n  - guardrail_name: my-guardrail\n    litellm_params:\n      mode: pre_call\n\n# after\nguardrails:\n  - guardrail_name: my-guardrail\n    litellm_params:\n      guardrail: aim\n      mode: pre_call","handlingStrategy":"validation","validationCode":"# Lint guardrail config before startup\nimport yaml\n\ncfg = yaml.safe_load(open('config.yaml'))\nfor g in cfg.get('guardrails', []):\n    lp = g.get('litellm_params') or {}\n    if not lp.get('guardrail'):\n        raise SystemExit(f\"guardrail '{g.get('guardrail_name')}' missing litellm_params.guardrail\")","typeGuard":"from typing import Any\n\ndef is_complete_guardrail_entry(entry: dict[str, Any]) -> bool:\n    \"\"\"True when a guardrails entry names itself and declares a guardrail type.\"\"\"\n    return (\n        isinstance(entry.get('guardrail_name'), str)\n        and bool((entry.get('litellm_params') or {}).get('guardrail'))\n    )","tryCatchPattern":null,"preventionTips":["Validate guardrails blocks with a YAML schema (e.g. pydantic) in CI","Use litellm's documented guardrail config examples as templates rather than hand-writing from memory","Watch indentation: type keys belong under litellm_params"],"tags":["guardrail","config","validation","startup"],"backgroundTag":"invalid-config-value","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}