Skip to content

Conversation

AdrGav941
Copy link
Contributor

@AdrGav941 AdrGav941 commented Sep 22, 2025

Description

This PR adds support for the JailbreakV_28k dataset to PyRIT.

Addresses #1007

Changes Made:

  • Added integration for JailbreakV_28k
  • Normalizes and associates the datasets "policy" column with harm-category
  • Allows for filtering on harm categories (policy values)

Files Added/Modified:

  • pyrit/datasets/fetch_jailbreakv_28k_dataset.py - Main implementation
  • pyrit/datasets/init.py - Added exports for new functions
  • tests/unit/datasets/test_fetch_jailbreakv_28k_dataset.py - Unit tests
  • tests\integration\datasets\test_fetch_datasets.py - Integration tests added

Tests and Documentation

  • PyTest parametrized testing for filtering and choice of text field (dataset has jailbreak and redteaming prompts)
  • Dataset mocking with both text fields and policy mapped to harm_category

Copy link
Contributor

@romanlutz romanlutz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting started on this!

The integration test for datasets is missing, but I suspect it will require a custom one as the dataset is meant to be multimodal (see other comment).

"fetch_jbb_behaviors_dataset",
"fetch_jbb_behaviors_by_harm_category",
"fetch_jbb_behaviors_by_jbb_category",
"fetch_jailbreakv_28k_dataset",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind keeping these alphabetical? I realize we missed out on that before but no better time to fix it than now 🙂

Comment on lines +62 to +63
The dataset license: mit
authors: Weidi Luo, Siyuan Ma, Xiaogeng Liu, Chaowei Xiao, Xiaoyu Guo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The dataset license: mit
authors: Weidi Luo, Siyuan Ma, Xiaogeng Liu, Chaowei Xiao, Xiaoyu Guo
The dataset license: MIT
Authors: Weidi Luo, Siyuan Ma, Xiaogeng Liu, Chaowei Xiao, Xiaoyu Guo

Comment on lines +115 to +134
if image_abs_path:
group_id = uuid.uuid4()
text_seed_prompt = SeedPrompt(
value=item.get(text_field, ""),
harm_categories=[policy],
prompt_group_id=group_id,
data_type="text",
**common_metadata, # type: ignore[arg-type]
)
image_seed_prompt = SeedPrompt(
value=image_abs_path,
harm_categories=[policy],
prompt_group_id=group_id,
data_type="image_path",
**common_metadata, # type: ignore[arg-type]
)
seed_prompts.append(text_seed_prompt)
seed_prompts.append(image_seed_prompt)
else:
missing_images += 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if image_abs_path:
group_id = uuid.uuid4()
text_seed_prompt = SeedPrompt(
value=item.get(text_field, ""),
harm_categories=[policy],
prompt_group_id=group_id,
data_type="text",
**common_metadata, # type: ignore[arg-type]
)
image_seed_prompt = SeedPrompt(
value=image_abs_path,
harm_categories=[policy],
prompt_group_id=group_id,
data_type="image_path",
**common_metadata, # type: ignore[arg-type]
)
seed_prompts.append(text_seed_prompt)
seed_prompts.append(image_seed_prompt)
else:
missing_images += 1
if not image_abs_path:
missing_images += 1
continue
group_id = uuid.uuid4()
text_seed_prompt = SeedPrompt(
value=item.get(text_field, ""),
harm_categories=[policy],
prompt_group_id=group_id,
data_type="text",
**common_metadata, # type: ignore[arg-type]
)
image_seed_prompt = SeedPrompt(
value=image_abs_path,
harm_categories=[policy],
prompt_group_id=group_id,
data_type="image_path",
**common_metadata, # type: ignore[arg-type]
)
seed_prompts.append(text_seed_prompt)
seed_prompts.append(image_seed_prompt)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e., move the second case to first and remove indentation

Comment on lines +140 to +144
if not seed_prompts:
raise ValueError(
"JailBreakV-28K fetch produced 0 prompts. "
"Likely caused by all items returned after filtering having invalid image paths."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how many are currently missing? Should we have a cutoff (>0) at which point it should error out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the vast majority are missing, making this dataset not as useful as previously expected. I have started a discussion on HF about adding the full images folder which currently is only contained a zip file held in a separate cloud drive.

assert sum(p.data_type == "text" for p in jailbreakv_28k.prompts) == len(jailbreakv_28k.prompts) / 2
assert sum(p.data_type == "image_path" for p in jailbreakv_28k.prompts) == len(jailbreakv_28k.prompts) / 2
except Exception as e:
pytest.skip(f"Integration test skipped due to: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip? why not fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I am not sure why I was simply going off of what I thought was the convention based on previously merged custom integration tests (jbb dataset integration)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants