microsoft/autogen · error · ValueError
JSON content must be a dict
Error message
JSON content must be a dict
What it means
ChromaDBVectorMemory's internal text converter (used to turn MemoryContent into text for embedding/storage) accepts JSON mime type only when the inner content is a dict. A JSON content that is a list, string, or scalar raises this ValueError before the item is embedded.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py:298
except Exception as e:
logger.error(f"Failed to get/create collection: {e}")
raise
def _extract_text(self, content_item: str | MemoryContent) -> str:
"""Extract searchable text from content."""
if isinstance(content_item, str):
return content_item
content = content_item.content
mime_type = content_item.mime_type
if mime_type in [MemoryMimeType.TEXT, MemoryMimeType.MARKDOWN]:
return str(content)
elif mime_type == MemoryMimeType.JSON:
if isinstance(content, dict):
# Store original JSON string representation
return str(content).lower()
raise ValueError("JSON content must be a dict")
elif isinstance(content, Image):
raise ValueError("Image content cannot be converted to text")
else:
raise ValueError(f"Unsupported content type: {mime_type}")
def _calculate_score(self, distance: float) -> float:
"""Convert ChromaDB distance to a similarity score."""
if self._config.distance_metric == "cosine":
return 1.0 - (distance / 2.0)
return 1.0 / (1.0 + distance)
async def update_context(
self,
model_context: ChatCompletionContext,
) -> UpdateContextResult:
messages = await model_context.get_messages()
if not messages:
return UpdateContextResult(memories=MemoryQueryResult(results=[]))View on GitHub (pinned to 027ecf0a37)
Solutions
- Wrap list/scalar payloads in a dict before creating MemoryContent.
- Use MemoryMimeType.TEXT for already-serialized JSON strings.
- Validate content shape at the point where MemoryContent objects are constructed.
Example fix
# before
await memory.add(MemoryContent(content="[1, 2, 3]", mime_type=MemoryMimeType.JSON))
# after
await memory.add(MemoryContent(content={"items": [1, 2, 3]}, mime_type=MemoryMimeType.JSON)) Defensive patterns
Strategy: type-guard
Validate before calling
from autogen_core.memory import MemoryContent, MemoryMimeType
if c.mime_type == MemoryMimeType.JSON:
assert isinstance(c.content, dict), "ChromaDB memory JSON content must be a dict"
await memory.add(c) Type guard
def is_valid_json_memory_content(c) -> bool:
if c.mime_type != MemoryMimeType.JSON:
return True
return isinstance(c.content, dict) Prevention
- Validate MemoryContent shape at construction, not at memory.add time.
- Wrap JSON arrays in a dict and use TEXT mime for serialized strings.
When it happens
Trigger: Calling memory.add() / update_context() with MemoryContent(content=<list or str>, mime_type=MemoryMimeType.JSON); the converter runs during ingestion and rejects non-dict JSON.
Common situations: Storing JSON arrays or pre-stringified JSON in ChromaDB memory; upstream producers emitting list payloads; reusing the same content objects across memory backends with mismatched expectations.
Related errors
- JSON content must be a dict
- Image content cannot be converted to text
- Unsupported content type: {mime_type}
- Image content cannot be converted to text
- Unsupported content type: {mime_type}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/e19dc91ad3cc3a87.
Report an issue: GitHub.