BerriAI/litellm · error · HTTPException

Policy '{request.policy_name}' not found. Create the policy

Error message

Policy '{request.policy_name}' not found. Create the policy first.

What it means

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.

Source

Thrown at litellm/proxy/policy_engine/policy_endpoints.py:768

        "keys": [],
        "models": [],
        "created_at": "2024-01-01T00:00:00Z",
        "updated_at": "2024-01-01T00:00:00Z"
    }
    ```
    """
    from litellm.proxy.policy_engine.policy_validator import PolicyValidator
    from litellm.proxy.proxy_server import llm_router, prisma_client

    if prisma_client is None:
        raise HTTPException(status_code=500, detail="Database not connected")

    try:
        # Verify the policy has a production version (attachments resolve against production)
        policies = await get_policy_registry().get_all_policies_from_db(prisma_client, version_status="production")
        policy_names: Final = {p.policy_name for p in policies}
        if request.policy_name not in policy_names:
            raise HTTPException(
                status_code=404,
                detail=f"Policy '{request.policy_name}' not found. Create the policy first.",
            )

        # Reject concrete team/key/model scope entries that don't resolve to a real
        # entity. Wildcard patterns are allowed through (they may match zero today).
        scope_errors: Final = await PolicyValidator(
            prisma_client=prisma_client, llm_router=llm_router
        ).find_invalid_scope_entries(
            policy_name=request.policy_name,
            teams=request.teams,
            keys=request.keys,
            models=request.models,
        )
        if scope_errors:
            raise HTTPException(status_code=400, detail=" | ".join(e.message for e in scope_errors))

        created_by: Final = user_api_key_dict.user_id

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Create the policy first via the policy creation endpoint, then attach or reference it.
  2. Check policy_name for typos against the existing policy list.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at litellm/proxy/policy_engine/policy_endpoints.py:768 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/63003273a7b4a760. Report an issue: GitHub.