From 6f62f225fec3fe726b9e378b5864287cda4258db Mon Sep 17 00:00:00 2001 From: Vinay Umrethe <175500353+Vinay-Umrethe@users.noreply.github.com> Date: Sun, 15 Nov 2026 04:40:27 +0000 Subject: [PATCH] fix: Prevent private dataset names leaking into the model card If the model is uploaded publicly, but the datasets are private, then skip adding them. If the model is uploaded privately, and the datasets are also private, then adding them to the datasets list is reasonably fine for privacy. --- src/heretic/main.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/heretic/main.py b/src/heretic/main.py index 7b74fec..a1bdfbb 100644 --- a/src/heretic/main.py +++ b/src/heretic/main.py @@ -1303,7 +1303,10 @@ def run(): card.data.base_model = settings.model # Add the datasets that were used, in the - # `datasets` field of the model card. + # `datasets` field of the model card. Private + # datasets are skipped when the model is uploaded + # publicly. And when the model is uploaded privately, + # the private datasets that were used are listed. flat_specifications: list[ SingleDatasetSpecification ] = [] @@ -1315,13 +1318,19 @@ def run(): else: flat_specifications.extend(specification) - datasets: list[str] = list( - dict.fromkeys( - specification.dataset - for specification in flat_specifications - if is_hf_path(specification.dataset) + datasets: list[str] = [] + for specification in flat_specifications: + if not is_hf_path(specification.dataset): + continue + dataset_info = huggingface_hub.dataset_info( + specification.dataset, ) - ) + # Prevent private dataset names from leaking on + # public models and/or cards. + if not private and dataset_info.private: + continue + datasets.append(specification.dataset) + datasets = list(dict.fromkeys(datasets)) if datasets: card.data.datasets = datasets