[Bug]: pii_redaction_mapper rewrites media paths in images/videos lists outside redact_keys
Before Reporting
- [ ] I have asked the Data-Juicer Q&A Copilot (available on Doc Site, DingTalk, or Discord), but the problem still persists.
- [x] I have pulled the latest code of main branch to run again and the bug still existed.
- [ ] I have read the README carefully and no error occurred during the installation process. (Otherwise, we recommend that you can ask a question using the Question template)
Search before reporting
- [x] I have searched the Data-Juicer issues and found no similar bugs.
OS
Ubuntu 24.04 (WSL)
Installation Method
from source
Data-Juicer Version
main @ 792de57
Python Version
3.12
Describe the bug
pii_redaction_mapper rewrites every string in every list field of the sample, not only the keys in redact_keys. Multimodal samples keep their media paths in images / videos / audios lists, so with the default mask_paths=True those paths become [PATH_REDACTED] and later ops can't load the files. Only paths under /home, /Users, /tmp and similar get hit, so it shows up as some samples silently losing their media.
The cause is the last step of process_single, self._redact_value(sample). Its comment says it redacts "nested file_path/path/arguments anywhere in sample", and for dicts it only touches PII_VALUE_KEYS, but the list branch of _redact_value redacts every string item:
https://github.com/datajuicer/data-juicer/blob/792de57/data_juicer/ops/mapper/pii_redaction_mapper.py#L247-L260
To Reproduce
from data_juicer.ops.mapper.pii_redaction_mapper import PiiRedactionMapper
op = PiiRedactionMapper(text_key="text", redact_keys=["text"])
out = op.process_single({
"text": "contact [email protected]",
"images": ["/home/alice/photos/cat.jpg", "/data/imgs/dog.png"],
"videos": ["/tmp/clip.mp4"],
"tags": ["user_id: 42", "plain tag"],
})
print(out["images"]) # ['[PATH_REDACTED]', '/data/imgs/dog.png']
print(out["videos"]) # ['[PATH_REDACTED]']
print(out["tags"]) # ['user_id[ID_REDACTED]', 'plain tag']
images, videos and tags are not in redact_keys, but they are rewritten anyway.
Expected behavior
Fields outside redact_keys are only touched under PII_VALUE_KEYS (as the comment says), and media keys (image_key, video_key, audio_key) are never rewritten.
A fix could be either of these. Which one would you prefer?
- In the nested walk, only recurse into dicts inside lists, so plain strings in lists are left alone unless their key is in
redact_keys.test_redact_value_recurses_nested_dicts_and_listscurrently expects a string in a list (items[0]) to be redacted, so that test would change. - Keep the broad walk, but skip the op's media keys.
I can send a PR once you pick one.
Thanks for reporting this! Iād prefer option 1. Please update the affected test and add a regression test for the media paths.