{"record":{"id":"50c8fd2974e8b857","repo":"BerriAI/litellm","slug":"prisma-client-not-initialized-50c8fd","errorCode":null,"errorMessage":"Prisma client not initialized","messagePattern":"Prisma client not initialized","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_endpoints.py","lineNumber":403,"sourceCode":"        \"guardrail_info\": {\n            \"description\": \"Bedrock content moderation guardrail\"\n        },\n        \"created_at\": \"2023-11-09T12:34:56.789Z\",\n        \"updated_at\": \"2023-11-09T12:34:56.789Z\"\n    }\n    ```\n    \"\"\"\n    from litellm.proxy.guardrails.guardrail_registry import IN_MEMORY_GUARDRAIL_HANDLER\n    from litellm.proxy.proxy_server import prisma_client\n\n    if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:\n        raise HTTPException(\n            status_code=403,\n            detail=\"Admin access required to manage guardrails\",\n        )\n\n    if prisma_client is None:\n        raise HTTPException(status_code=500, detail=\"Prisma client not initialized\")\n\n    try:\n        result = await GUARDRAIL_REGISTRY.add_guardrail_to_db(guardrail=request.guardrail, prisma_client=prisma_client)\n\n        guardrail_name: Final = result.get(\"guardrail_name\", \"Unknown\")\n        guardrail_id: Final = result.get(\"guardrail_id\", \"Unknown\")\n\n        try:\n            IN_MEMORY_GUARDRAIL_HANDLER.initialize_guardrail(guardrail=cast(Guardrail, result), source=\"db\")\n            verbose_proxy_logger.info(\n                \"Immediate sync: Successfully initialized guardrail '%s' (ID: %s)\", guardrail_name, guardrail_id\n            )\n        except (ValueError, TypeError) as init_error:\n            # Configuration error — roll back the DB write so the guardrail isn't orphaned\n            if prisma_client is not None:\n                try:\n                    await _delete_guardrail_row(prisma_client, where={\"guardrail_id\": guardrail_id})\n                except Exception as rollback_err:","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_endpoints.py#L385-L421","documentation":"POST /guardrails raises HTTP 500 'Prisma client not initialized' when the proxy global prisma_client is None, i.e. the proxy was started without a database. Guardrails are persisted in the DB (guardrails table) and hot-synced into memory, so a DB is mandatory for this endpoint.","triggerScenarios":"Starting litellm proxy without DATABASE_URL (or with database: None in config) and then calling POST /guardrails.","commonSituations":"Local dev servers run in zero-config mode for chat completions only; Kubernetes deployment missing the DATABASE_URL secret; Postgres URL typo so prisma_client construction was skipped; hitting management endpoints on a UI-less headless instance.","solutions":["Set DATABASE_URL to a reachable Postgres instance in the proxy environment and restart (LiteLLM auto-runs migrations on startup)","If using docker, ensure the env var is passed: docker run -e DATABASE_URL=postgresql://...","Verify with GET /health/liveliness and proxy startup logs that Prisma connected before retrying","If you only need static guardrails, define them under guardrails: in config.yaml instead of the API — no DB needed at runtime for config-declared guardrails"],"exampleFix":"# before\nlitellm --config config.yaml  # no DATABASE_URL\ncurl -X POST http://localhost:4000/guardrails ...  # 500\n\n# after\nexport DATABASE_URL=\"postgresql://user:pass@host:5432/litellm\"\nlitellm --config config.yaml\ncurl -X POST http://localhost:4000/guardrails -H 'Authorization: Bearer sk-master-key' ...","handlingStrategy":"validation","validationCode":"import os, requests\n\nif not os.environ.get(\"DATABASE_URL\"):\n    raise RuntimeError(\"Proxy needs DATABASE_URL before guardrail CRUD\")\nhealth = requests.get(f\"{proxy}/health/liveliness\", timeout=5)\nhealth.raise_for_status()","typeGuard":null,"tryCatchPattern":"try:\n    r = requests.post(f\"{proxy}/guardrails\", json=guardrail, headers=h, timeout=30)\n    r.raise_for_status()\nexcept requests.HTTPError as e:\n    if e.response is not None and e.response.status_code == 500 and \"Prisma\" in e.response.text:\n        raise RuntimeError(\"Proxy is DB-less; set DATABASE_URL and restart, or define guardrails in config.yaml\") from e\n    raise","preventionTips":["Deploy guardrails only on DB-backed proxy instances","Add a pre-flight check for DATABASE_URL in deployment scripts","Use config.yaml guardrails for stateless setups"],"tags":["litellm-proxy","guardrails","prisma","database","configuration"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}