> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Enable Injection Defense • AI Agents Framework

> enable_injection_defense: Enable prompt injection defense globally for all agents.

# enable\_injection\_defense

Function

> This function is defined in the [**security**](https://praison.ai/docs/sdk/reference/praisonai/modules/security.md) 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

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def enable_injection_defense(extra_patterns: Optional[List[str]], block_threshold: Optional[int], trusted_sources: Optional[List[str]]) -> Dict[str, str]
```

## Parameters

**extra\_patterns** `Optional`

Additional regex patterns to detect (appended to defaults).

**block\_threshold** `Optional[int]`

Override the threat level that triggers blocking. 3 = CRITICAL, 2 = HIGH (default), 1 = MEDIUM.

**trusted\_sources** `Optional`

Source names that bypass blocking (in addition to defaults).

### Returns

**Returns** `Dict[str, str]`

\{"before\_tool": str, "before\_agent": str}

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
>>> from praisonai.security import enable_injection_defense
    >>> enable_injection_defense()
```

## Uses

* `ThreatLevel`
* `InjectionDefense`
* `add_hook`
* `defense.create_hook`
* `defense.create_agent_hook`

## Used By

* [`enable_security`](../functions/enable_security)

## Source

> [card] [View on GitHub](https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai/praisonai/security/__init__.py#L85)
>
> `praisonai/security/__init__.py` at line 85


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.