{"record":{"id":"2ec22e3b71ffbdee","repo":"microsoft/semantic-kernel","slug":"the-record-does-not-have-the-cosmos-item-id-prope","errorCode":null,"errorMessage":"The record does not have the {COSMOS_ITEM_ID_PROPERTY_NAME} property.","messagePattern":"The record does not have the (.+?) property\\.","errorType":"exception","errorClass":"VectorStoreModelDeserializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_cosmos_db.py","lineNumber":1002,"sourceCode":"        key_field_name = self.definition.key_name\n        for record in records:\n            serialized_record = {**record, COSMOS_ITEM_ID_PROPERTY_NAME: record[key_field_name]}\n            if key_field_name != COSMOS_ITEM_ID_PROPERTY_NAME:\n                # Remove the key field from the serialized record\n                serialized_record.pop(key_field_name, None)\n\n            serialized_records.append(serialized_record)\n\n        return serialized_records\n\n    @override\n    def _deserialize_store_models_to_dicts(self, records: Sequence[Any], **kwargs: Any) -> Sequence[dict[str, Any]]:\n        deserialized_records = []\n\n        key_field_name = self.definition.key_name\n        for record in records:\n            if COSMOS_ITEM_ID_PROPERTY_NAME not in record:\n                raise VectorStoreModelDeserializationException(\n                    f\"The record does not have the {COSMOS_ITEM_ID_PROPERTY_NAME} property.\"\n                )\n\n            deserialized_record = {**record, key_field_name: record[COSMOS_ITEM_ID_PROPERTY_NAME]}\n            if key_field_name != COSMOS_ITEM_ID_PROPERTY_NAME:\n                # Remove the id property from the deserialized record\n                deserialized_record.pop(COSMOS_ITEM_ID_PROPERTY_NAME, None)\n\n            deserialized_records.append(deserialized_record)\n\n        return deserialized_records\n\n    @override\n    async def ensure_collection_exists(self, **kwargs) -> None:\n        indexing_policy = kwargs.pop(\"indexing_policy\", _create_default_indexing_policy_nosql(self.definition))\n        vector_embedding_policy = kwargs.pop(\n            \"vector_embedding_policy\", _create_default_vector_embedding_policy(self.definition)\n        )","sourceCodeStart":984,"sourceCodeEnd":1020,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_cosmos_db.py#L984-L1020","documentation":"During deserialization the store expects every returned Cosmos document to contain the canonical 'id' property (COSMOS_ITEM_ID_PROPERTY_NAME). If a record lacks it, VectorStoreModelDeserializationException is raised before mapping id back to the data model's key field. This guards the key-rename logic (which copies record[id] into the model key field) from a KeyError.","triggerScenarios":"A document retrieved from Cosmos (via get/upsert return or a manual dict passed through deserialization) has no 'id' field. Typically this happens when raw records not created through the store are deserialized, or a projection/query selected only some fields and omitted id.","commonSituations":"Using a SELECT projection that excludes id and feeding the result into deserialization; documents written by another system that uses a different id convention; or partially-constructed dicts passed to internal deserialize paths.","solutions":["Ensure all stored documents include the 'id' property; write records through the store's upsert/create so the serializer always sets COSMOS_ITEM_ID_PROPERTY_NAME.","If selecting a subset of fields, always include id in the projection so deserialization succeeds.","When ingesting external documents, map their identifier into the 'id' field before storing/deserializing."],"exampleFix":"// before\nawait store.get([record_id])  # document in Cosmos is missing the 'id' field\n// after\n# ensure documents are written with 'id' present:\nawait store.upsert({\"id\": record_id, **other_fields})\n","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.azure_cosmos_db import COSMOS_ITEM_ID_PROPERTY_NAME\nfor rec in records:\n    if COSMOS_ITEM_ID_PROPERTY_NAME not in rec:\n        raise ValueError(f\"Record missing required '{COSMOS_ITEM_ID_PROPERTY_NAME}'\")","typeGuard":"def has_id(rec: dict) -> bool:\n    return COSMOS_ITEM_ID_PROPERTY_NAME in rec","tryCatchPattern":null,"preventionTips":["Always write records through the store's upsert/create so 'id' is set automatically.","Include 'id' in any SELECT projection used for deserialization.","Map external identifiers into the 'id' field before storing."],"tags":["azure-cosmos-db","deserialization","data-model"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}