{"record":{"id":"fb049a7595e3b217","repo":"chroma-core/chroma","slug":"source-key-must-be-str-or-key-got-type-v-name","errorCode":null,"errorMessage":"source_key must be str or Key, got {type(v).__name__}","messagePattern":"source_key must be str or Key, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/types.py","lineNumber":1712,"sourceCode":"    ] = None  # key to source the vector from (accepts str or Key)\n    hnsw: Optional[HnswIndexConfig] = None\n    spann: Optional[SpannIndexConfig] = None\n\n    @field_validator(\"source_key\", mode=\"before\")\n    @classmethod\n    def validate_source_key_field(cls, v: Any) -> Optional[str]:\n        \"\"\"Convert Key objects to strings automatically. Accepts both str and Key types.\"\"\"\n        if v is None:\n            return None\n        # Import Key at runtime to avoid circular import\n        from chromadb.execution.expression.operator import Key as KeyType\n\n        if isinstance(v, KeyType):\n            v = v.name  # Extract string from Key\n        elif isinstance(v, str):\n            pass  # Already a string\n        else:\n            raise ValueError(f\"source_key must be str or Key, got {type(v).__name__}\")\n\n        # Validate: only #document is allowed if key starts with #\n        if v.startswith(\"#\") and v != \"#document\":\n            raise ValueError(\n                \"source_key cannot begin with '#'. \"\n                \"The only valid key starting with '#' is Key.DOCUMENT or '#document'.\"\n            )\n\n        return v  # type: ignore[no-any-return]\n\n    @field_validator(\"embedding_function\", mode=\"before\")\n    @classmethod\n    def validate_embedding_function_field(cls, v: Any) -> Any:\n        # Use the existing validate_embedding_function for proper validation\n        if v is None:\n            return v\n        if callable(v):\n            # Use the existing validation function","sourceCodeStart":1694,"sourceCodeEnd":1730,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/types.py#L1694-L1730","documentation":"Error \"source_key must be str or Key, got {type(v).__name__}\" thrown in chroma-core/chroma.","triggerScenarios":"Thrown at chromadb/api/types.py:1712 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}