Skip to content

Claude Conversations Importer Fails with TypeError on None Content Values #236

@calebpickerconsulting

Description

@calebpickerconsulting

Claude Conversations Importer Fails with TypeError on None Content Values

Description

The Claude conversations importer fails with a TypeError: sequence item 2: expected str instance, NoneType found when importing conversations that have None values in the content text fields. This occurs when trying to join text content from messages.

Steps to Reproduce

  1. Export Claude conversations that contain messages with null content text
  2. Run basic-memory import claude conversations
  3. Import fails with TypeError

Error Output

PS C:\Users\[Username]\OneDrive\Desktop> basic-memory import claude conversations

Importing chats from conversations.json...writing to C:\Users\[Username]\basic-memory\conversations
Failed to import Claude conversations
Traceback (most recent call last):
  File "C:\Users\[Username]\AppData\Roaming\uv\tools\basic-memory\Lib\site-packages\basic_memory\importers\claude_conversations_importer.py", line 156, in _format_chat_markdown
    content = " ".join(c.get("text", "") for c in msg["content"])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 2: expected str instance, NoneType found

Analysis

After analyzing my conversations.json file (309 conversations), I found:

  • 29,079 content items with text: null values
  • The issue is in line 156 of claude_conversations_importer.py
  • Some content array items have text fields that are None instead of strings

Example problematic structure:

{
  "content": [
    {
      "type": "text",
      "text": "Valid text here"
    },
    {
      "type": "text", 
      "text": null  // This causes the TypeError
    }
  ]
}

Proposed Solution

Replace line 156 in _format_chat_markdown:

# Current (buggy) code:
content = " ".join(c.get("text", "") for c in msg["content"])

# Fixed code:
content = " ".join(c.get("text", "") for c in msg["content"] if c and c.get("text") is not None)

This filters out None values before joining.

Workaround

Users can work around this by preprocessing their JSON file:

import json

# Read conversations
with open('conversations.json', 'r', encoding='utf-8') as f:
    data = json.load(f)

# Fix None values
for conv in data:
    for msg in conv.get('chat_messages', []):
        if 'content' in msg and isinstance(msg['content'], list):
            for content in msg['content']:
                if content and isinstance(content, dict) and content.get('text') is None:
                    content['text'] = ""

# Write fixed file
with open('conversations.json', 'w', encoding='utf-8') as f:
    json.dump(data, f, ensure_ascii=False, indent=2)

Environment

  • OS: Windows 11
  • Python version: (from UV tools environment)
  • basic-memory version: (latest)

Impact

This bug prevents users from importing Claude conversation history if any messages contain null text values, which appears to be common in Claude exports (affecting ~10% of messages in my export).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions