> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.
> For full documentation content, see https://docs.nvidia.com/nemo/guardrails/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.library.prompt_security.actions

Prompt/Response protection using Prompt Security.

## Module Contents

### Functions

| Name                                                                                           | Description                                       |
| ---------------------------------------------------------------------------------------------- | ------------------------------------------------- |
| [`protect_text`](#nemoguardrails-library-prompt_security-actions-protect_text)                 | Protects the given user\_prompt or bot\_response. |
| [`protect_text_mapping`](#nemoguardrails-library-prompt_security-actions-protect_text_mapping) | Mapping for protect\_text action.                 |
| [`ps_protect_api_async`](#nemoguardrails-library-prompt_security-actions-ps_protect_api_async) | Calls Prompt Security Protect API asynchronously. |

### Data

[`log`](#nemoguardrails-library-prompt_security-actions-log)

### API

```python
nemoguardrails.library.prompt_security.actions.protect_text(
    user_prompt: typing.Optional[str] = None,
    bot_response: typing.Optional[str] = None,
    kwargs = {}
)
```

async

Protects the given user\_prompt or bot\_response.
Args:
user\_prompt: The user message to protect.
bot\_response: The bot message to protect.
Returns:
A dictionary with the following items:

* is\_blocked: True if the text should be blocked, False otherwise.
* is\_modified: True if the text should be modified, False otherwise.
* modified\_text: The modified text if is\_modified is True, None otherwise.
  Raises:
  ValueError is returned in one of the following cases:

1. If PS\_PROTECT\_URL env variable is not set.
2. If PS\_APP\_ID env variable is not set.
3. If no user\_prompt and no bot\_response is provided.

```python
nemoguardrails.library.prompt_security.actions.protect_text_mapping(
    result: dict
) -> bool
```

Mapping for protect\_text action.

**Returns:** `bool`

True if the response should be blocked (i.e. if "is\_blocked" is True),

```python
nemoguardrails.library.prompt_security.actions.ps_protect_api_async(
    ps_protect_url: str,
    ps_app_id: str,
    prompt: typing.Optional[str] = None,
    system_prompt: typing.Optional[str] = None,
    response: typing.Optional[str] = None,
    user: typing.Optional[str] = None
)
```

async

Calls Prompt Security Protect API asynchronously.

**Parameters:**

the URL of the protect endpoint given by Prompt Security.

//\[REGION].prompt.security/api/protect where REGION is eu, useast or apac

the application ID given by Prompt Security (similar to an API key).

//\[REGION].prompt.security/ where REGION is eu, useast or apac

the user message to protect.

the system message for context.

the bot message to protect.

the user ID or username for context.

**Returns:**

A dictionary with the following items:

```python
nemoguardrails.library.prompt_security.actions.log = logging.getLogger(__name__)
```