Skip to content

Probe.probe() raises IndexError when the prompt set is empty (translation can produce an empty set) #2026

Description

@feiiiiii5

Summary

In garak/probes/base.py, Probe.probe() indexes prompts[0] without checking that the list is non-empty:

prompts = copy.deepcopy(self.prompts)
...
preparation_bar = tqdm.tqdm(total=len(prompts), ...)   # len is fine with 0
if isinstance(prompts[0], str):                          # IndexError when empty

Repro

Observed on main (also flagged in PR #2022): tests/probes/test_probes.py::test_probe_prompt_translation[probes.sysprompt_extraction.SystemPromptExtraction] fails locally with IndexError: list index out of range at base.py:402 because the translated prompt set comes back empty under the local langprovider. len(prompts) is used for the progress bar two lines earlier, so the empty set reaches the subscript instead of producing zero attempts.

Expected behavior

A probe with an empty (or emptied-by-translation) prompt set should return no attempts — or raise a clear error naming the probe — rather than an IndexError deep in the execution path.

Suggested fix direction

if not prompts:
    logging.warning("probe %s has an empty prompt set", self.probename)
    return []

before the isinstance(prompts[0], str) check.

Happy to open a PR with a regression test.

Metadata

Metadata

Assignees

No one assigned

    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