# Recovering Chat History from AI Platform Exports After an Account Restriction
This guide explains how to recover your AI chat history after an account restriction. It covers appealing the restriction and requesting a data export, identifying the structure of the export files, and writing a Python script that uses only the standard library to clean and merge multiple exports into an offline reader. The example structures must be adjusted to match your own files.
AI chat platforms have become working tools for many developers. Design discussions, code refactoring, and technology selection often span hundreds of conversation turns. If an account is restricted, those conversations may become inaccessible. This article covers how to appeal and request an export, how to parse the export package, how to clean the data and merge multiple exports, and how to build an offline reader. The scripts use only the Python standard library. The example structures need to be adjusted to match the files you actually have.
1. Confirm the Restriction Reason and the Appeal Channel
After an account is restricted, the first step is to find the reason the platform gives. The platform’s safety policies usually explain which behaviors trigger restrictions and describe the appeal process and its deadlines. If the reason involves a policy violation, follow the platform’s decision. Do not try to bypass risk controls, and do not use other accounts to get around the restriction. These actions can cause your data request to be rejected and may lead to more serious consequences.
You can submit a data access request at the same time as your appeal. Most platforms’ privacy policies allow users to access and export their personal data. Under China’s Personal Information Protection Law (PIPL), individuals have the right to access and copy their personal information. If you are in the European Union or the United Kingdom, you can cite the right of access and the right to data portability under the GDPR. Specific terms depend on each platform’s policies and on local law. For complex cases, consult a qualified professional.
Your support ticket should include three things: the account identifier, the scope of data you want to export, and your preferred delivery method. If the platform’s export link requires you to log in again, explain that you can no longer access the account and ask support to deliver the data as an offline file or by another method.
2. Understand the Structure of the Export Package
After you receive the archive, do not read the contents right away. First, list all the files, then check the top-level structure of each one. File names vary widely between platforms. Common names include conversations.json, user.json, and chat.html. Base your work on the files you actually exported, not on another person’s file list.
Exported JSON usually follows one of two layouts. In the first, each conversation contains a messages or chat_messages array directly. This layout is easy to read. In the second, messages are stored in a mapping dictionary and linked into branches through parent and children fields. You need to rebuild the order from the node relationships or from timestamps. The table below lists the fields the script needs to support:
| Meaning | Possible field names |
|---|---|
| Conversation ID | uuid, id |
| Conversation title | name, title |
| Message ID | uuid, id |
| Sender | sender, role, author.role |
| Timestamp | timestamp, created_at, create_time |
| Body content | text, content, content.parts, or text blocks in a content array |
Attachments are usually stored as separate metadata. The cleaned output in this article keeps only the message text.
Run the following code to inspect the key names and determine which structure the file uses:
import jsonwith open("conversations.json", encoding="utf-8") as f:data = json.load(f)if isinstance(data, dict):print("Top level is a dict. Keys:", list(data.keys())[:20])data = data.get("conversations", [])if data:print("Keys of the first conversation:", list(data[0].keys()))
Match the output against the table to confirm the field names. If the key names do not match the table, edit the field lists in the script in the next section.
3. Cleaning Script: Detect the Structure and Filter Empty Messages
The script takes one or more exported JSON files as input and outputs a single JSON file in a unified format. Its main logic works as follows.
It reads files as UTF-8. If a file cannot be parsed or its top-level structure is unexpected, the script prints a warning and skips that file without stopping the entire process. For each message, the script tries several field names in turn and converts the various body structures into plain text. Messages with empty bodies are discarded. The conversation ID, title, message role, and timestamp are kept.
import jsonimport sysfrom pathlib import PathROLE_KEYS = ("sender", "role", "author")ID_KEYS = ("uuid", "id")TIME_KEYS = ("timestamp", "created_at", "create_time")def extract_text(value):"""Convert string, list, and dict content structures into plain text."""if value is None:return ""if isinstance(value, str):return value.strip()if isinstance(value, list):parts = (extract_text(item) for item in value)return "\n".join(p for p in parts if p)if isinstance(value, dict):for key in ("text", "content", "parts"):if key in value:return extract_text(value[key])return ""def first_value(obj, keys):for key in keys:value = obj.get(key)if value not in (None, ""):return valuereturn Nonedef get_role(msg):value = first_value(msg, ROLE_KEYS)if isinstance(value, dict):value = value.get("role") or value.get("name")return str(value or "unknown")def iter_messages(convo):"""Support both flat message lists and mapping node trees."""for key in ("chat_messages", "messages"):items = convo.get(key)if isinstance(items, list):return itemsmapping = convo.get("mapping")if isinstance(mapping, dict):nodes = (node.get("message") for node in mapping.values
