{"record":{"id":"66becc9812b77326","repo":"BerriAI/litellm","slug":"policy-with-name-request-policy-name-already-e","errorCode":null,"errorMessage":"Policy with name '{request.policy_name}' already exists","messagePattern":"Policy with name '(.+?)' already exists","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"litellm/proxy/policy_engine/policy_endpoints.py","lineNumber":208,"sourceCode":"    ```\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\n\n    if prisma_client is None:\n        raise HTTPException(status_code=500, detail=\"Database not connected\")\n\n    try:\n        created_by: Final = user_api_key_dict.user_id\n        result: Final = await get_policy_registry().add_policy_to_db(\n            policy_request=request,\n            prisma_client=prisma_client,\n            created_by=created_by,\n        )\n        return result\n    except Exception as e:\n        verbose_proxy_logger.exception(\"Error creating policy: %s\", e)\n        if \"unique constraint\" in str(e).lower():\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Policy with name '{request.policy_name}' already exists\",\n            )\n        raise HTTPException(status_code=500, detail=str(e))\n\n\n# ─────────────────────────────────────────────────────────────────────────────\n# Policy Versioning Endpoints (must be before /policies/{policy_id} to avoid path conflicts)\n# ─────────────────────────────────────────────────────────────────────────────\n\n\n@router.get(\n    \"/policies/name/{policy_name}/versions\",\n    tags=[\"Policies\"],\n    dependencies=[Depends(user_api_key_auth)],\n    response_model=PolicyVersionListResponse,\n)\nasync def list_policy_versions(policy_name: str):","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/policy_engine/policy_endpoints.py#L190-L226","documentation":"Uniqueness guard when creating a policy: the underlying add_policy_to_db failed with a 'unique constraint' error, i.e. a policy with the same policy_name already exists, so the request is rejected as a 400.","triggerScenarios":"Thrown at litellm/proxy/policy_engine/policy_endpoints.py:208 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose a different policy_name, or update the existing policy instead of creating a new one.","Delete the existing policy first if a fresh create is intended."],"exampleFix":null,"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"}