Principle:Norrrrrrr lyn WAInjectBench Dynamic Detector Loading Text
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Plugin_Systems |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
A plugin architecture pattern that dynamically loads detector modules at runtime based on a user-specified name, enabling extensible text-based prompt injection detection.
Description
Dynamic module loading allows a system to discover and instantiate components at runtime without hardcoding imports. In the text detection pipeline, the user specifies a detector name via CLI (e.g., --detector promptguard), and the system uses Python's importlib.import_module to load the corresponding module from the detector_text/ package. Each detector module must expose a detect(file_path: str) -> List[int] function, forming a uniform plugin interface.
This pattern decouples the orchestration logic from individual detector implementations, making it trivial to add new detectors by simply dropping a new Python file into the package directory.
Usage
Use this pattern when building an evaluation harness that must support multiple interchangeable detection algorithms. The CLI user selects which detector to run, and the system loads it without any code changes.
Theoretical Basis
The plugin pattern relies on:
- Convention over configuration: Module names map directly to file names in a known package.
- Uniform interface: All plugins implement the same function signature (
detect(file_path) -> List[int]). - Late binding: The import happens at runtime, not at module load time.
# Abstract plugin loading pattern
module = importlib.import_module(f"{package_name}.{plugin_name}")
result = module.detect(input_data)