chroma-core/chroma · error · ValueError

source_key cannot begin with '#'. The only valid key startin

Error message

source_key cannot begin with '#'. The only valid key starting with '#' is Key.DOCUMENT or '#document'.

What it means

Error "source_key cannot begin with '#'. The only valid key starting with '#' is Key.DOCUMENT or '#document'." thrown in chroma-core/chroma.

Source

Thrown at chromadb/api/types.py:1716

    @field_validator("source_key", mode="before")
    @classmethod
    def validate_source_key_field(cls, v: Any) -> Optional[str]:
        """Convert Key objects to strings automatically. Accepts both str and Key types."""
        if v is None:
            return None
        # Import Key at runtime to avoid circular import
        from chromadb.execution.expression.operator import Key as KeyType

        if isinstance(v, KeyType):
            v = v.name  # Extract string from Key
        elif isinstance(v, str):
            pass  # Already a string
        else:
            raise ValueError(f"source_key must be str or Key, got {type(v).__name__}")

        # Validate: only #document is allowed if key starts with #
        if v.startswith("#") and v != "#document":
            raise ValueError(
                "source_key cannot begin with '#'. "
                "The only valid key starting with '#' is Key.DOCUMENT or '#document'."
            )

        return v  # type: ignore[no-any-return]

    @field_validator("embedding_function", mode="before")
    @classmethod
    def validate_embedding_function_field(cls, v: Any) -> Any:
        # Use the existing validate_embedding_function for proper validation
        if v is None:
            return v
        if callable(v):
            # Use the existing validation function
            validate_embedding_function(v)
            return v
        raise ValueError("embedding_function must be callable or None")

View on GitHub (pinned to aecdd12c8a)

When it happens

Trigger: Thrown at chromadb/api/types.py:1716 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/cf22a043f400c28f. Report an issue: GitHub.