chroma-core/chroma · error · TypeError
Expected dict for GroupBy, got
Error message
Expected dict for GroupBy, got {type(data).__name__} What it means
Raised by GroupBy.from_dict when the group_by specification is not a dict — e.g. a list of keys or a string was passed instead of the expected mapping like {"keys": [...], "aggregate": {...}} (an empty dict {} is valid and means no grouping).
Solutions
- Pass group_by as a dict, e.g. {"keys": ["category"], "aggregate": {...}}, or omit it for default grouping
- Unwrap the value from any enclosing structure before calling from_dict
- Construct a GroupBy object directly if you already have one
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at chromadb/execution/expression/operator.py:1510 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/dd9688b9399b709e.
Report an issue: GitHub.
Appendix: source
Thrown at chromadb/execution/expression/operator.py:1510
def to_dict(self) -> Dict[str, Any]:
"""Convert the GroupBy to a dictionary for JSON serialization"""
# Default GroupBy (no keys, no aggregate) serializes to {}
if not self.keys or self.aggregate is None:
return {}
result: Dict[str, Any] = {"keys": _keys_to_strings(self.keys)}
result["aggregate"] = self.aggregate.to_dict()
return result
@staticmethod
def from_dict(data: Dict[str, Any]) -> "GroupBy":
"""Create GroupBy from dictionary.
Examples:
- {} -> GroupBy() (default, no grouping)
- {"keys": ["category"], "aggregate": {"$min_k": {"keys": ["#score"], "k": 3}}}
"""
if not isinstance(data, dict):
raise TypeError(f"Expected dict for GroupBy, got {type(data).__name__}")
# Empty dict returns default GroupBy (no grouping)
if not data:
return GroupBy()
# Non-empty dict requires keys and aggregate
if "keys" not in data:
raise ValueError("GroupBy requires 'keys' field")
if "aggregate" not in data:
raise ValueError("GroupBy requires 'aggregate' field")
keys = data["keys"]
if not isinstance(keys, (list, tuple)):
raise TypeError(f"GroupBy keys must be a list, got {type(keys).__name__}")
if not keys:
raise ValueError("GroupBy keys cannot be empty")
aggregate_data = data["aggregate"]View on GitHub (pinned to aecdd12c8a)