Repository navigation
FIX Make WebInjection dataset selections independent of preloaded memory - #2996
Merged
Roman Lutz (romanlutz) merged 5 commits intoOct 9, 2026
Conversation
…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
Co-authored-by: Copilot App <[email protected]>
Roman Lutz (romanlutz)
approved these changes
Oct 9, 2026
Roman Lutz (romanlutz)
left a comment
Contributor
There was a problem hiding this comment.
I'll make a small addition, otherwise looks fantastic.
Co-authored-by: Copilot App <[email protected]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2993.
An explicit
--dataset-namesselection forgarak.web_injectionnow 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:Root cause.
_load_dataset_values_asyncread all four web-injection datasets fromCentralMemoryby hardcoded name, ignoringself._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 afterload_default_datasetshad populated memory.Changes (all in
pyrit/scenario/scenarios/garak/web_injection.py):_TECHNIQUE_REQUIRED_DATASETSdeclares the source datasets each technique reads in_build_prompts_for_technique.StringAssemblyDataExfiluses built-in seeds and needs none._validate_runtime_configurationchecks the selected techniques against the selected dataset names, asApiKeyandLatentInjectionalready 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 oneDatasetConstraintError(aValueErrorsubclass)._load_dataset_values_asyncreads only the selected datasets, so data outside the selection is never consulted.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_asyncpreviewed with a placeholderdataset_names=["missing"]alongside techniques that need real datasets; it now selects the datasets those techniques need. Itsmax_dataset_sizeand 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_hashfor 7 valid configurations onmainand on this branch: defaults withalland with the default techniques, an explicit selection of all four datasets, and minimal selections fortask_xss,exfil,markdown_xss, andxss(with a reordered--dataset-names). All 7 are byte-identical, soVERSIONstays 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 realLoadDefaultDatasetsinitializer scoped to the four web-injection datasets. No model calls.--techniques task_xss)main(e7d2619)DatasetConstraintErrornaminggarak_web_html_jsDatasetConstraintErrorDatasetConstraintErrorTests 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:test_real_local_datasets_load_async.The new tests fail on
main(14 failures). Separately, deliberately droppinggarak_web_html_jsfromtask_xss's entry, or adding an unneeded dataset tomarkdown_xss's entry, each fails exactly the matching guard case.doc/scanner/garak.pyandgarak.ipynbdocument the per-technique dataset requirements and a complete--dataset-namesexample.Checks run locally:
uv run pre-commit run --files <changed files>: all hooks passuv run ty check pyrit tests/unit: no diagnostics in the changed files; the full output is identical tomainuv run -m pytest -n 2 --dist=loadfile tests/unit/scenario tests/unit/backend/test_scenario_configuration_resolver.py tests/unit/setup: 2000 passedmain: 100% (14 of 14 changed lines inweb_injection.py)