{"record":{"id":"83a7ba8027dacdb7","repo":"BerriAI/litellm","slug":"prisma-client-is-not-initialized-database-connect","errorCode":null,"errorMessage":"Prisma client is not initialized. Database connection required for LiteLLM skills.","messagePattern":"Prisma client is not initialized\\. Database connection required for LiteLLM skills\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"litellm/llms/litellm_proxy/skills/handler.py","lineNumber":58,"sourceCode":"\n    data: Final = prisma_skill.model_dump()\n\n    if data.get(\"file_content\") is not None:\n        if isinstance(data[\"file_content\"], str):\n            data[\"file_content\"] = base64.b64decode(data[\"file_content\"])\n\n    return LiteLLM_SkillsTable(**data)\n\n\nclass LiteLLMSkillsHandler:\n    \"\"\"CRUD for skills stored in ``litellm_skillstable``.\"\"\"\n\n    @staticmethod\n    async def _get_prisma_client():\n        from litellm.proxy.proxy_server import prisma_client\n\n        if prisma_client is None:\n            raise ValueError(\"Prisma client is not initialized. Database connection required for LiteLLM skills.\")\n        return prisma_client\n\n    @staticmethod\n    async def create_skill(\n        data: NewSkillRequest,\n        user_id: str | None = None,\n        user_api_key_dict: UserAPIKeyAuth | None = None,\n    ) -> LiteLLM_SkillsTable:\n        prisma_client: Final = await LiteLLMSkillsHandler._get_prisma_client()\n\n        skill_id: Final = f\"{LITELLM_SKILL_ID_PREFIX}{uuid.uuid4()}\"\n        owner: Final = get_primary_resource_owner_scope(user_api_key_dict) or user_id\n        if owner is None:\n            # Identity-less callers (no user_id / team_id / org_id /\n            # api_key / token) can't be uniquely stamped on the row.\n            # Stamping a placeholder would let any two such callers see\n            # each other's skills via the shared owner. ValueError keeps\n            # this module FastAPI-free per the project layering rule.","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/litellm_proxy/skills/handler.py#L40-L76","documentation":"All LiteLLM skills CRUD operations go through the proxy's shared Prisma client (litellm.proxy.proxy_server.prisma_client). That object only exists when the proxy started with a working database connection; if it is None — DATABASE_URL unset or the DB connection failed at startup — _get_prisma_client raises ValueError for every skills call.","triggerScenarios":"Hitting the proxy's skills endpoints (create/get/update/delete skill) or calling LiteLLMSkillsHandler methods directly while the proxy server runs without a database; unit tests importing the handler without initializing prisma; DB went down after startup and the client was never constructed.","commonSituations":"Starting litellm proxy without DATABASE_URL (in-memory mode) but exposing skills routes; Prisma migration/connection failure at boot that was missed in the logs; CI tests exercising skills without a database fixture.","solutions":["Set DATABASE_URL (e.g. postgres://...) in the proxy's environment and restart it so Prisma connects","Check proxy startup logs for Prisma connect/migration errors and fix them","Run prisma migrations if the schema is not yet initialized","Confirm you are calling the proxy instance that actually has the database configured, not a separate bare one"],"exampleFix":"# before\nlitellm --config config.yaml --port 4000  # started without DATABASE_URL\n# -> POST /v1/skills -> 500 ValueError: Prisma client is not initialized\n\n# after\nexport DATABASE_URL=\"postgresql://user:pass@host:5432/litellm\"\nlitellm --config config.yaml --port 4000  # prisma_client connects at startup","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"DATABASE_URL\"):\n    raise SystemExit(\"Skills endpoints require a database — set DATABASE_URL before starting the proxy\")\n# alternatively at request time:\n# from litellm.proxy.proxy_server import prisma_client\n# if prisma_client is None: return JSONResponse(status_code=503, content={\"error\": \"database not configured\"})","typeGuard":null,"tryCatchPattern":"try:\n    skill = await LiteLLMSkillsHandler.get_skill(skill_id, user_api_key_dict=auth)\nexcept ValueError as e:\n    if \"Prisma client is not initialized\" in str(e):\n        raise HTTPException(status_code=503, detail=\"Skills unavailable: database not configured\") from e\n    raise","preventionTips":["Always start the proxy with DATABASE_URL when skills routes are exposed","Run startup health checks that assert prisma_client is not None before accepting traffic","In tests, initialize a Prisma test client (or skip skills tests) instead of hitting the None guard"],"tags":["litellm-proxy","skills","prisma","database","initialization"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}