[feat] support messages column as JSON string in iterable datasets#147
Merged
[feat] support messages column as JSON string in iterable datasets#147
Conversation
Add automatic JSON string decoding for the messages column in iterable dataset loaders. This allows parquet files to store chat messages as JSON strings instead of nested Arrow structs, avoiding schema inference issues with deeply nested message formats.
kcz358
reviewed
Mar 19, 2026
Collaborator
kcz358
left a comment
There was a problem hiding this comment.
It's okay to do this but usually we want parquet to be field structure so simply inserting a field like messages as str into parquet might loosing quite a lot info. But this ops is okay here as would not hurt other operations.
Collaborator
Author
|
Thanks for the review! Agreed that structured parquet fields are preferred in general. This is mainly a compatibility fallback for datasets that already store messages as JSON strings (common in ShareGPT-format datasets on HF Hub). The isinstance check has zero overhead on properly structured data. LGTM to merge? |
Collaborator
|
Config the ssh or ghp key for the future for verified signature. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Parquet's Arrow schema inference struggles with deeply nested, heterogeneous structures like OpenAI-format chat messages. A single
messagescolumn may contain varying content types (text,image_url,video) with different nested fields across rows, leading to schema conflicts during both file creation and multi-file loading.A pragmatic and widely-used workaround is to store the
messagescolumn as a JSON-encoded string. This is already common practice in the community — many ShareGPT-format datasets on HuggingFace Hub use this approach. However, the current iterable dataset loaders assumemessagesis always a nativelist[dict]and crash on string input with:Modifications
Add an
isinstance(messages, str)check withjson.loads()fallback at all entry points wheremessagesis read from data:Qwen3VLIterableDataset.load_from_json()— handles video/image multimodal dataVisionSFTIterableDataset.load_from_json()— handles image-only dataVisionSFTIterableDataset.load_from_hf()— handles HuggingFace dataset formatThe change is backward-compatible: native
list[dict]messages pass through theisinstancecheck with zero overhead.