{"record":{"id":"8d58836233d52c4a","repo":"microsoft/graphrag","slug":"cosmosdb-storage-requires-database-name","errorCode":null,"errorMessage":"CosmosDB Storage requires 'database_name'.","messagePattern":"CosmosDB Storage requires 'database_name'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/graphrag-storage/graphrag_storage/azure_cosmos_storage.py","lineNumber":67,"sourceCode":"    _container_name: str\n    _encoding: str\n    _namespace: str\n\n    def __init__(\n        self,\n        database_name: str,\n        container_name: str,\n        connection_string: str | None = None,\n        account_url: str | None = None,\n        encoding: str = \"utf-8\",\n        namespace: str = \"\",\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Create a CosmosDB key-value storage instance.\"\"\"\n        logger.info(\"Creating CosmosDB key-value storage\")\n        if not database_name:\n            msg = \"CosmosDB Storage requires 'database_name'.\"\n            raise ValueError(msg)\n\n        if connection_string is not None and account_url is not None:\n            msg = \"Specify either 'connection_string' or 'account_url', not both.\"\n            raise ValueError(msg)\n\n        if connection_string:\n            self._cosmos_client = CosmosClient.from_connection_string(connection_string)\n        elif account_url:\n            self._cosmos_client = CosmosClient(\n                url=account_url,\n                credential=DefaultAzureCredential(),\n            )\n        else:\n            msg = \"CosmosDB Storage requires 'connection_string' or 'account_url'.\"\n            raise ValueError(msg)\n\n        self._encoding = encoding\n        self._database_name = database_name","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag-storage/graphrag_storage/azure_cosmos_storage.py#L49-L85","documentation":"AzureCosmosStorage's constructor requires a database_name because CosmosDB organizes all containers inside a named database; without it the SDK has no target to create or fetch. The check runs before any client is constructed, so nothing is connected yet when it fires. It is a configuration-validation error from graphrag-storage's CosmosDB key-value store.","triggerScenarios":"Instantiating AzureCosmosStorage (directly or via StorageFactory with type azure_cosmos) with database_name=None, an empty string, or omitting it from the storage config kwargs.","commonSituations":"Copied a blob/file-storage config where database_name is not a field; YAML/env override left the value blank; relied on a connection string assuming the database is implied (it is not in CosmosDB).","solutions":["Set database_name in the storage config (e.g. type: azure_cosmos, database_name: mygraphrag) or pass database_name=\"mydb\" to the constructor","If using settings.yaml, verify the key sits under the correct storage section and is not shadowed by an env-var prefix mistake","Confirm the database exists in your Cosmos account or that the account has permission to create it"],"exampleFix":"# before\nstorage = AzureCosmosStorage(connection_string=conn_str)\n# after\nstorage = AzureCosmosStorage(connection_string=conn_str, database_name=\"graphrag\")","handlingStrategy":"validation","validationCode":"if not cfg.get(\"database_name\"):\n    raise SystemExit(\"Set storage.database_name before creating Cosmos storage\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate required cosmos keys (database_name, one credential) before constructing storage","Keep a config schema/validator for settings.yaml"],"tags":["cosmosdb","config","graphrag-storage","validation"],"backgroundTag":"missing-required-config","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}