Principle:Protectai Llm guard Input Scanner Interface
| Knowledge Sources | |
|---|---|
| Domains | Software_Design, Security, Plugin_Architecture |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
An abstract base class pattern that defines the interface all input scanners must implement, enabling pluggable composition of security scanners in the prompt scanning pipeline.
Description
The input scanner interface defines a single method contract: scan(prompt: str) -> tuple[str, bool, float]. All input scanners must inherit from the Scanner base class and implement this method. This enables the scan_prompt function to iterate over any list of scanners polymorphically.
The return contract is:
- str: The (possibly modified) prompt after scanning.
- bool: True if the prompt passes the scanner, False if it fails.
- float: Risk score in [0, 1] where 0 is no risk, or -1 if not applicable.
Usage
Implement this interface when creating custom input scanners for LLM Guard. Custom scanners can then be added to the scanner pipeline alongside built-in scanners.
Theoretical Basis
# Abstract interface for input scanners
class Scanner(ABC):
@abstractmethod
def scan(self, prompt: str) -> tuple[str, bool, float]:
"""
Scan a prompt for security issues.
Args:
prompt: Input text to scan.
Returns:
(sanitized_prompt, is_valid, risk_score)
"""
...