chroma-core/chroma · error · ValueError
source_key cannot begin with '#'. The only valid key…
Error message
source_key cannot begin with '#'. The only valid key starting with '#' is Key.DOCUMENT or '#document'.
What it means
Raised by the VectorIndexConfig source_key pydantic field validator when the source_key string starts with '#'. The '#' prefix is reserved for special document keys, and the only legal one is '#document' (Key.DOCUMENT); user metadata field names may not begin with '#'.
Solutions
- Use a regular (non-'#') key, or Key.DOCUMENT/'#document' explicitly.
- Drop the leading '#' from the key name.
Defensive patterns
Strategy: validation
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.
Appendix: 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)