{"record":{"id":"193665a0f3688ed4","repo":"langchain-ai/deepagents","slug":"store-item-content-must-be-a-str-or-legacy-li","errorCode":null,"errorMessage":"Store item `content` must be a `str` or legacy `list[str]`, got {type(raw_content).__name__}.","messagePattern":"Store item `content` must be a `str` or legacy `list\\[str\\]`, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/backends/store.py","lineNumber":196,"sourceCode":"                content is joined without modifying the persisted item. Includes\n                `created_at` and `modified_at` when present.\n\n        Raises:\n            ValueError: If the store item has no content.\n            TypeError: If content is neither a string nor a legacy list of strings.\n        \"\"\"\n        raw_content = store_item.value.get(\"content\")\n        if raw_content is None:\n            msg = f\"Store item does not contain valid content field. Got: {store_item.value.keys()}\"\n            raise ValueError(msg)\n\n        if isinstance(raw_content, list) and all(isinstance(line, str) for line in raw_content):\n            content = \"\\n\".join(raw_content)\n        elif isinstance(raw_content, str):\n            content = raw_content\n        else:\n            msg = f\"Store item `content` must be a `str` or legacy `list[str]`, got {type(raw_content).__name__}.\"\n            raise TypeError(msg)\n\n        result = FileData(\n            content=content,\n            encoding=store_item.value.get(\"encoding\", \"utf-8\"),\n        )\n        if \"created_at\" in store_item.value and isinstance(store_item.value[\"created_at\"], str):\n            result[\"created_at\"] = store_item.value[\"created_at\"]\n        if \"modified_at\" in store_item.value and isinstance(store_item.value[\"modified_at\"], str):\n            result[\"modified_at\"] = store_item.value[\"modified_at\"]\n        return result\n\n    def _convert_file_data_to_store_value(self, file_data: FileData) -> dict[str, Any]:\n        \"\"\"Convert `FileData` to a dict suitable for `store.put()`.\n\n        Args:\n            file_data: The `FileData` to convert.\n\n        Returns:","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/backends/store.py#L178-L214","documentation":"Store item `content` must be either a `str` or a legacy `list[str]` (joined with newlines during conversion). Any other type (bytes, dict, int, or a list with non-string elements) is rejected with a TypeError naming the offending Python type.","triggerScenarios":"Writing store items whose `content` is bytes, a dict, an int, or a mixed list like `['a', 2]`, then reading them back through StoreBackend's `_convert_store_item_to_file_data`.","commonSituations":"Encoding text as bytes before storing; storing structured JSON payloads as dict content; mixed-type lists from unparsed user input; version drift where a newer writer changed the content type.","solutions":["Write `content` as a `str` (or list of str lines) when putting items into the store","Decode bytes with `.decode('utf-8')` before storing; serialize dicts with json.dumps()","Normalize mixed lists to strings (`[str(x) for x in lines]`) before writing","Add a write-side check that rejects non-str/list[str] content early"],"exampleFix":"// before\nstore.put(ns, key, {'content': b'hello'})\n// after\nstore.put(ns, key, {'content': b'hello'.decode('utf-8')})","handlingStrategy":"type-guard","validationCode":"def normalize_content(content):\n    if isinstance(content, bytes):\n        return content.decode('utf-8')\n    if isinstance(content, (dict, list)) and not all(isinstance(l, str) for l in (content if isinstance(content, list) else [])):\n        import json\n        return json.dumps(content)\n    return content\nstore.put(ns, key, {'content': normalize_content(raw)})","typeGuard":"def is_valid_content(content: object) -> bool:\n    if isinstance(content, str):\n        return True\n    return isinstance(content, list) and all(isinstance(l, str) for l in content)","tryCatchPattern":"try:\n    data = backend.read('/a.txt')\nexcept TypeError as exc:\n    if 'must be a `str` or legacy `list[str]`' in str(exc):\n        rewrite_item_with_valid_content('/a.txt')\n    else:\n        raise","preventionTips":["Decode bytes and serialize dicts to JSON strings before storing content","Validate content type at write time, not read time","Keep legacy list[str] entries all-strings; normalize mixed lists on write","Pin writer versions so schema changes are migration events, not surprises"],"tags":["store","type-error","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}