Skip to main content

enable_injection_defense

Function
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.

Signature

Parameters

Optional
Additional regex patterns to detect (appended to defaults).
Optional[int]
Override the threat level that triggers blocking. 3 = CRITICAL, 2 = HIGH (default), 1 = MEDIUM.
Optional
Source names that bypass blocking (in addition to defaults).

Returns

str
{“before_tool”: str, “before_agent”: str}

Usage

Uses

  • ThreatLevel
  • InjectionDefense
  • add_hook
  • defense.create_hook
  • defense.create_agent_hook

Used By

Source

View on GitHub

praisonai/security/__init__.py at line 85