{"record":{"id":"63003273a7b4a760","repo":"BerriAI/litellm","slug":"policy-request-policy-name-not-found-create-t","errorCode":null,"errorMessage":"Policy '{request.policy_name}' not found. Create the policy first.","messagePattern":"Policy '(.+?)' not found\\. Create the policy first\\.","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"litellm/proxy/policy_engine/policy_endpoints.py","lineNumber":768,"sourceCode":"        \"keys\": [],\n        \"models\": [],\n        \"created_at\": \"2024-01-01T00:00:00Z\",\n        \"updated_at\": \"2024-01-01T00:00:00Z\"\n    }\n    ```\n    \"\"\"\n    from litellm.proxy.policy_engine.policy_validator import PolicyValidator\n    from litellm.proxy.proxy_server import llm_router, prisma_client\n\n    if prisma_client is None:\n        raise HTTPException(status_code=500, detail=\"Database not connected\")\n\n    try:\n        # Verify the policy has a production version (attachments resolve against production)\n        policies = await get_policy_registry().get_all_policies_from_db(prisma_client, version_status=\"production\")\n        policy_names: Final = {p.policy_name for p in policies}\n        if request.policy_name not in policy_names:\n            raise HTTPException(\n                status_code=404,\n                detail=f\"Policy '{request.policy_name}' not found. Create the policy first.\",\n            )\n\n        # Reject concrete team/key/model scope entries that don't resolve to a real\n        # entity. Wildcard patterns are allowed through (they may match zero today).\n        scope_errors: Final = await PolicyValidator(\n            prisma_client=prisma_client, llm_router=llm_router\n        ).find_invalid_scope_entries(\n            policy_name=request.policy_name,\n            teams=request.teams,\n            keys=request.keys,\n            models=request.models,\n        )\n        if scope_errors:\n            raise HTTPException(status_code=400, detail=\" | \".join(e.message for e in scope_errors))\n\n        created_by: Final = user_api_key_dict.user_id","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/policy_engine/policy_endpoints.py#L750-L786","documentation":"Precondition guard when attaching a policy: the named policy has no production version in the DB/registry (it was never created or never promoted), and attachments resolve against production, so the attach is rejected.","triggerScenarios":"Thrown at litellm/proxy/policy_engine/policy_endpoints.py:768 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Create the policy first via the policy creation endpoint, then attach or reference it.","Check policy_name for typos against the existing policy list."],"exampleFix":null,"handlingStrategy":"type-guard","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-14T00:17:10.932Z"}