Enable Injection Defense • AI Agents Framework
enable_injection_defense: Enable prompt injection defense globally for all agents.
enable_injection_defense
Function
</div>
This function is defined in the security module.
Enable prompt injection defense globally for all agents.
Registers hooks on BEFORE_TOOL and BEFORE_AGENT events that scan inputs through a 6-check pipeline and block critical threats.
.. warning:: This registers on the process-global `praisonaiagents.hooks registry, so the policy applies to every Agent in the process. In a multi-tenant host (e.g. praisonai serve) do not rely on this for per-tenant isolation. To scope or tear down later, keep the returned hook IDs and remove them via praisonaiagents.hooks.remove_hook`.
Signature
def enable_injection_defense(extra_patterns: Optional[List[str]], block_threshold: Optional[int], trusted_sources: Optional[List[str]]) -> Dict[str, str]Parameters
OptionalAdditional regex patterns to detect (appended to defaults).
Optional[int]Override the threat level that triggers blocking. 3 = CRITICAL, 2 = HIGH (default), 1 = MEDIUM.
OptionalSource names that bypass blocking (in addition to defaults).
Returns
Dict[str, str]{”before_tool”: str, “before_agent”: str}
Usage
>>> from praisonai.security import enable_injection_defense
>>> enable_injection_defense()Uses
ThreatLevelInjectionDefenseadd_hookdefense.create_hookdefense.create_agent_hook
Used By
Source
View on GitHubpraisonai/security/__init__.py at line 85