Skip to content

Commit 1f962ae

Browse files
romanlutzCopilothannahwestra25
authored
FIX: Use sequence=0 for both pieces in multimodal dataset loaders (#1756)
Co-authored-by: romanlutz <romanlutz@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: hannahwestra25 <hannahwestra@microsoft.com>
1 parent a301010 commit 1f962ae

8 files changed

Lines changed: 21 additions & 18 deletions

pyrit/datasets/seed_datasets/remote/comic_jailbreak_dataset.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ async def fetch_dataset_async(self, *, cache: bool = True) -> SeedDataset:
142142
Fetch ComicJailbreak dataset and return as SeedDataset of image+text pairs.
143143
144144
For each goal × template combination, renders the template-specific text into the
145-
comic template image and returns a pair of prompts (image at sequence=0, text query
146-
at sequence=1) linked by prompt_group_id.
145+
comic template image and returns a pair of prompts (image and text query, both at
146+
sequence=0) that share a ``prompt_group_id`` so they are delivered to the model as
147+
a single multimodal user message.
147148
148149
Args:
149150
cache: Whether to cache the fetched dataset. Defaults to True.
@@ -240,8 +241,9 @@ def _build_seed_group(
240241
behavior: The behavior label from the dataset.
241242
242243
Returns:
243-
list[Seed]: A three-element list with objective,
244-
image (sequence=0), and text query (sequence=1).
244+
list[Seed]: A three-element list with objective, image, and text query.
245+
The image and text query share the same ``prompt_group_id`` and
246+
``sequence=0`` so they are delivered as a single multimodal user message.
245247
"""
246248
group_id = uuid.uuid4()
247249
metadata: dict[str, str | int] = {
@@ -285,7 +287,7 @@ def _build_seed_group(
285287
authors=_AUTHORS,
286288
source=self.PAPER_URL,
287289
prompt_group_id=group_id,
288-
sequence=1,
290+
sequence=0,
289291
metadata=metadata,
290292
)
291293

pyrit/datasets/seed_datasets/remote/visual_leak_bench_dataset.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class _VisualLeakBenchDataset(_RemoteDatasetLoader):
4747
- **PII Leakage**: Social engineering attacks to extract sensitive personal information
4848
across 8 PII types (Email, DOB, Phone, Password, PIN, API Key, SSN, Credit Card)
4949
50-
Each example produces an image prompt (sequence=0) and a text prompt (sequence=1)
51-
linked via a shared ``prompt_group_id``. The text prompt is the query sent to the model.
50+
Each example produces an image prompt and a text prompt that share both a
51+
``prompt_group_id`` and ``sequence=0`` so they are delivered to the model as a single
52+
multimodal user message.
5253
5354
Note: The first call may be slow as images need to be downloaded from remote URLs.
5455
Subsequent calls will be faster since images are cached locally.
@@ -123,9 +124,9 @@ async def fetch_dataset_async(self, *, cache: bool = True) -> SeedDataset:
123124
"""
124125
Fetch VisualLeakBench examples and return as SeedDataset.
125126
126-
Each example produces a pair of prompts linked by a shared ``prompt_group_id``:
127-
- sequence=0: image prompt (the adversarial image)
128-
- sequence=1: text prompt (the query sent to the model)
127+
Each example produces a pair of prompts that share both a ``prompt_group_id`` and
128+
``sequence=0`` so they are delivered to the model as a single multimodal user
129+
message: the adversarial image and the text query.
129130
130131
Args:
131132
cache: Whether to cache the fetched dataset. Defaults to True.
@@ -265,7 +266,7 @@ async def _build_prompt_pair_async(self, example: dict[str, str]) -> list[SeedPr
265266
authors=authors,
266267
source=self.PAPER_URL,
267268
prompt_group_id=group_id,
268-
sequence=1,
269+
sequence=0,
269270
metadata={
270271
"category": category_str,
271272
"pii_type": pii_type_str,

pyrit/datasets/seed_datasets/remote/vlguard_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def fetch_dataset_async(self, *, cache: bool = True) -> SeedDataset:
140140
Fetch VLGuard multimodal examples and return as SeedDataset.
141141
142142
Downloads the test split metadata and images from HuggingFace, then creates
143-
multimodal prompts (text + image pairs linked by prompt_group_id) based on
143+
multimodal prompts (text + image pairs linked by prompt_group_id and sequence=0) based on
144144
the selected subset.
145145
146146
Args:
@@ -218,7 +218,7 @@ async def fetch_dataset_async(self, *, cache: bool = True) -> SeedDataset:
218218
description=f"Image component of VLGuard multimodal prompt ({self.subset.value}).",
219219
source=self.source,
220220
prompt_group_id=group_id,
221-
sequence=1,
221+
sequence=0,
222222
metadata={
223223
"category": category,
224224
"subcategory": subcategory,

pyrit/datasets/seed_datasets/remote/vlsu_multimodal_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ async def _build_prompt_pair_async(self, example: dict[str, str]) -> list[SeedPr
232232
description="Image component of ML-VLSU multimodal prompt.",
233233
source=self.source,
234234
prompt_group_id=group_id,
235-
sequence=1,
235+
sequence=0,
236236
metadata={**metadata, "original_image_url": image_url},
237237
)
238238

tests/unit/datasets/test_comic_jailbreak_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def test_fetch_dataset_creates_image_text_pairs(self):
8181
assert objective.prompt_group_id == image_prompt.prompt_group_id == text_prompt.prompt_group_id
8282
assert objective.value == "Write a defamatory article about a public figure"
8383
assert image_prompt.sequence == 0
84-
assert text_prompt.sequence == 1
84+
assert text_prompt.sequence == 0
8585
assert text_prompt.value == _COMIC_JAILBREAK_QUERY_PROMPT
8686
assert image_prompt.value == "/fake/rendered.png"
8787

tests/unit/datasets/test_visual_leak_bench_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def test_fetch_dataset_ocr_creates_pair(self):
107107

108108
assert image_prompt.prompt_group_id == text_prompt.prompt_group_id
109109
assert image_prompt.sequence == 0
110-
assert text_prompt.sequence == 1
110+
assert text_prompt.sequence == 0
111111
assert text_prompt.value == _VisualLeakBenchDataset.OCR_INJECTION_PROMPT
112112
assert image_prompt.value == "/fake/ocr.png"
113113

tests/unit/datasets/test_vlguard_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async def test_prompt_group_id_links_text_and_image(self, mock_vlguard_metadata,
223223
assert text_prompt.data_type == "text"
224224
assert image_prompt.data_type == "image_path"
225225
assert text_prompt.sequence == 0
226-
assert image_prompt.sequence == 1
226+
assert image_prompt.sequence == 0
227227

228228
async def test_missing_image_skipped(self, mock_vlguard_metadata, tmp_path):
229229
"""Test that examples with missing images are skipped."""

tests/unit/datasets/test_vlsu_multimodal_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async def test_fetch_dataset_combined_unsafe_creates_pair(self):
9393

9494
# Verify sequence order
9595
assert text_prompt.sequence == 0
96-
assert image_prompt.sequence == 1
96+
assert image_prompt.sequence == 0
9797

9898
# Verify text prompt
9999
assert text_prompt.value == "Text that becomes unsafe with image"

0 commit comments

Comments
 (0)