Skip to content

BUG: Garak and ML-VLSU loaders still load one example when max_examples is 0 or negative #3591

Closed

Description

Describe the bug

The Garak loaders (_GarakRemoteDataset in pyrit/datasets/seed_datasets/remote/garak_dataset.py and every subclass, such as the package hallucination, system prompt and audio datasets) and _VLSUMultimodalDataset (vlsu_multimodal_dataset.py) accept any integer for max_examples. They compare against the cap only after appending, so a cap below 1 never stops the first item:

  • _GarakNpmDataset(max_examples=0) and max_examples=-1 each load 1 seed.
  • _VLSUMultimodalDataset(max_examples=0) loads the first matching example's text and image pair: len(prompts) >= 0 * 2 is only checked after the pair is added.

This is the same pattern as max_examples in the ComicJailbreak loader (#3589).

Steps/Code to Reproduce

import asyncio
from unittest.mock import AsyncMock, patch

from pyrit.datasets.seed_datasets.remote.garak_package_hallucination_dataset import _GarakNpmDataset
from pyrit.datasets.seed_datasets.remote.vlsu_multimodal_dataset import _VLSUMultimodalDataset
from pyrit.setup.initialization import IN_MEMORY, initialize_pyrit_async

ROWS = [{"text": f"pkg{i}", "package_first_seen": "2010-01-01"} for i in range(3)]


async def main():
    await initialize_pyrit_async(memory_db_type=IN_MEMORY)
    for max_examples in (0, -1):
        try:
            loader = _GarakNpmDataset(max_examples=max_examples)
            with patch.object(loader, "_fetch_from_huggingface_async", new=AsyncMock(return_value=ROWS)):
                dataset = await loader.fetch_dataset_async()
            print(f"garak npm max_examples={max_examples}: {len(dataset.seeds)} seeds")
        except ValueError as e:
            print(f"garak npm max_examples={max_examples}: ValueError: {e}")
        try:
            _VLSUMultimodalDataset(max_examples=max_examples)
            print(f"ml_vlsu max_examples={max_examples}: accepted")
        except ValueError as e:
            print(f"ml_vlsu max_examples={max_examples}: ValueError: {e}")


asyncio.run(main())

Expected Results

A cap below 1 is rejected when the loader is created, as the ComicJailbreak fix for #3589 does:

garak npm max_examples=0: ValueError: max_examples must be at least 1 or None, got 0
ml_vlsu max_examples=0: ValueError: max_examples must be at least 1 or None, got 0
garak npm max_examples=-1: ValueError: max_examples must be at least 1 or None, got -1
ml_vlsu max_examples=-1: ValueError: max_examples must be at least 1 or None, got -1

Actual Results

garak npm max_examples=0: 1 seeds
ml_vlsu max_examples=0: accepted
garak npm max_examples=-1: 1 seeds
ml_vlsu max_examples=-1: accepted

Screenshots

N/A

Versions

  • OS: Windows 11
  • Python version: 3.11.9
  • PyRIT version: installed from main (6224d53) in editable mode

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions