Implementation:Norrrrrrr lyn WAInjectBench load detector text
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Plugin_Systems |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
Concrete tool for dynamically loading text detector modules at runtime using Python's importlib, provided by the WAInjectBench main_text module.
Description
The load_detector function in main_text.py takes a detector name string and uses importlib.import_module to load the corresponding module from the detector_text package. It raises a ValueError with a helpful message if the module is not found. Valid detector names include: kad, promptarmor, embedding-t, promptguard, datasentinel, and ensemble.
Usage
Import and call this function when you need to dynamically select a text detector at runtime based on user input from the --detector CLI argument.
Code Reference
Source Location
- Repository: WAInjectBench
- File: main_text.py (L8-20)
Signature
def load_detector(detector_name: str):
"""
Dynamically load the corresponding detector module.
Each detector module must implement a `detect(file_path)` function,
which takes a JSONL file path as input and outputs a list of detected IDs.
"""
import importlib
try:
module = importlib.import_module(f"detector_text.{detector_name}")
return module
except ImportError:
raise ValueError(f"Detector {detector_name} not found. "
f"Make sure you have a file under detector_text/ named {detector_name}.py")
Import
from main_text import load_detector
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| detector_name | str | Yes | Name of the detector module (e.g., "kad", "promptarmor", "embedding-t", "promptguard", "datasentinel") |
Outputs
| Name | Type | Description |
|---|---|---|
| module | module | Loaded Python module with a detect(file_path: str) -> List[int] function |
Usage Examples
Loading a Text Detector
# Load the PromptGuard detector
detector = load_detector("promptguard")
# Use the detector on a JSONL file
detect_ids = detector.detect("data/text/malicious/attack_scenario.jsonl")
print(f"Detected {len(detect_ids)} malicious samples: {detect_ids}")