Skip to content

FIX Make WebInjection dataset selections independent of preloaded memory - #2996

Merged
Roman Lutz (romanlutz) merged 5 commits into
microsoft:mainfrom
shashank03-dev:fix/web-injection-dataset-requirements
Oct 9, 2026
Merged

Roman Lutz (romanlutz) merged 5 commits into
microsoft:mainfrom
shashank03-dev:fix/web-injection-dataset-requirements

Conversation

@shashank03-dev

Copy link
Copy Markdown
Contributor

Description

Fixes #2993.

An explicit --dataset-names selection for garak.web_injection now has the same meaning no matter what memory already holds. Before prompts are built, the scenario checks that the selection includes every dataset the selected techniques read. An incomplete selection fails with an actionable error, identically with empty and preloaded memory:

Technique 'task_xss' requires dataset 'garak_web_html_js', which is missing from the selected dataset names (--dataset-names).

Root cause. _load_dataset_values_async read all four web-injection datasets from CentralMemory by hardcoded name, ignoring self._dataset_config.dataset_names (its docstring already said "each configured dataset"). Auto-fetch only loads the selected names, so a dataset left out of the selection was empty on a fresh backend, but was silently picked up after load_default_datasets had populated memory.

Changes (all in pyrit/scenario/scenarios/garak/web_injection.py):

  • _TECHNIQUE_REQUIRED_DATASETS declares the source datasets each technique reads in _build_prompts_for_technique. StringAssemblyDataExfil uses built-in seeds and needs none.
  • _validate_runtime_configuration checks the selected techniques against the selected dataset names, as ApiKey and LatentInjection already validate their selections. It runs before both the preview estimate and initialization and reads no data, so the result cannot depend on memory. All missing datasets are reported in one DatasetConstraintError (a ValueError subclass).
  • _load_dataset_values_async reads only the selected datasets, so data outside the selection is never consulted.
  • The empty-result fallback no longer tells users to preload datasets into memory, since preloading is exactly what hid the error.

Also fixed by the same check: the preview estimate previously reported 12 attacks for the incomplete selection, a run that cannot build on a fresh backend. It now raises the same error. test_web_injection_capped_techniques_use_generation_limits_async previewed with a placeholder dataset_names=["missing"] alongside techniques that need real datasets; it now selects the datasets those techniques need. Its max_dataset_size and assertions are unchanged, and the estimate still reads no data.

No change for valid configurations. I fingerprinted every seed group (objective and prompt values, in order) and the resume eval_hash for 7 valid configurations on main and on this branch: defaults with all and with the default techniques, an explicit selection of all four datasets, and minimal selections for task_xss, exfil, markdown_xss, and xss (with a reordered --dataset-names). All 7 are byte-identical, so VERSION stays at 2 and existing results resume unchanged.

Out of scope, per the issue: whether WebInjection should honor --max-dataset-size.

Proof

Each case runs in a fresh process with an in-memory SQLite database, goes through ScenarioConfigurationResolver.resolve_configuration (the code behind --techniques / --dataset-names), and uses the real local garak datasets. "Preloaded" runs the real LoadDefaultDatasets initializer scoped to the four web-injection datasets. No model calls.

Case (--techniques task_xss) main (e7d2619) This branch
Incomplete selection, empty memory Generic "produced no prompts ... loaded into CentralMemory" error DatasetConstraintError naming garak_web_html_js
Incomplete selection, preloaded memory Succeeds (12 prompts) Same DatasetConstraintError
Complete selection, empty memory Succeeds (12) Succeeds (12)
Defaults, empty memory Succeeds (12) Succeeds (12)
Incomplete selection, preview estimate (empty / preloaded) Reports 12 attacks Same DatasetConstraintError

Tests and Documentation

New tests in tests/unit/scenario/garak/test_web_injection.py, using the real in-memory database and the real local dataset fetch:

  • An incomplete selection fails with the exact message for both the preview estimate and initialization, parametrized over empty and preloaded memory, and leaves memory untouched (the check runs before any fetch).
  • A complete selection initializes with empty memory and fetches only the selected datasets. The default selection with empty memory is covered by the existing test_real_local_datasets_load_async.
  • Datasets in memory but outside the selection are not read.
  • Several missing datasets are reported together, in order.
  • A technique with no source datasets accepts any selection.
  • Guard tests tie the requirements table to the prompt builder: every concrete technique has an entry, and for each technique the declared datasets alone build prompts while removing any one of them builds none.

The new tests fail on main (14 failures). Separately, deliberately dropping garak_web_html_js from task_xss's entry, or adding an unneeded dataset to markdown_xss's entry, each fails exactly the matching guard case.

doc/scanner/garak.py and garak.ipynb document the per-technique dataset requirements and a complete --dataset-names example.

Checks run locally:

  • uv run pre-commit run --files <changed files>: all hooks pass
  • uv run ty check pyrit tests/unit: no diagnostics in the changed files; the full output is identical to main
  • uv run -m pytest -n 2 --dist=loadfile tests/unit/scenario tests/unit/backend/test_scenario_configuration_resolver.py tests/unit/setup: 2000 passed
  • Diff coverage against main: 100% (14 of 14 changed lines in web_injection.py)

…ements

An explicit --dataset-names selection for garak.web_injection now behaves the
same whatever memory already holds. Before building prompts, the scenario
checks that the selection includes every dataset the selected techniques read,
and fails with an actionable error naming each missing dataset.

_load_dataset_values_async read all four web-injection datasets from memory
by hardcoded name, ignoring the selection. Auto-fetch only loads selected
names, so an omitted dataset was empty on a fresh backend but silently picked
up after load_default_datasets had populated memory.

- Declare each technique's source datasets in _TECHNIQUE_REQUIRED_DATASETS.
- Check them in _validate_runtime_configuration, which runs before both the
  preview estimate and initialization and reads no data.
- Read only the selected datasets.
- Drop the fallback advice to preload datasets into memory.

Valid configurations build byte-identical seed groups with the same resume
identity, so VERSION is unchanged.

Fixes microsoft#2993
@romanlutz Roman Lutz (romanlutz) self-assigned this Oct 9, 2026

@romanlutz Roman Lutz (romanlutz) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll make a small addition, otherwise looks fantastic.

Roman Lutz (romanlutz) and others added 2 commits October 9, 2026 06:17
Reject inline seeds and seed groups during preview and initialization, while retaining empty named selections for built-in techniques.

Co-authored-by: Copilot App <[email protected]>
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 9, 2026
Merged via the queue into microsoft:main with commit 5536471 Oct 9, 2026
55 checks passed
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.

BUG: WebInjection dataset overrides depend on previously loaded datasets

2 participants