> This page is for version v0.24.1.
> For other versions, use one of these documentation indexes:
> - Latest (default): https://docs.nvidia.com/nemo/guardrails/latest/llms.txt
> - v0.24.1: https://docs.nvidia.com/nemo/guardrails/v0.24.1/llms.txt
> - v0.24.0: https://docs.nvidia.com/nemo/guardrails/v0.24.0/llms.txt
> - v0.23.0: https://docs.nvidia.com/nemo/guardrails/v0.23.0/llms.txt
> - v0.22.0: https://docs.nvidia.com/nemo/guardrails/v0.22.0/llms.txt

> 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 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_outcome`](#nemoguardrails-library-prompt_security-actions-_protect_text_outcome) | -                                                 |
| [`protect_text`](#nemoguardrails-library-prompt_security-actions-protect_text)                   | Protects the given user\_prompt or bot\_response. |
| [`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_outcome(
    result: dict,
    target: nemoguardrails.actions.rail_outcome.TransformTarget
) -> nemoguardrails.actions.rail_outcome.RailOutcome
```

```python
nemoguardrails.library.prompt_security.actions.protect_text(
    user_prompt: typing.Optional[str] = None,
    bot_response: typing.Optional[str] = None,
    http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None,
    kwargs = {}
) -> nemoguardrails.actions.rail_outcome.RailOutcome
```

async

Protects the given user\_prompt or bot\_response.

Provider results may allow, block, or transform the selected message.
Provider failures fail open. A bot response takes precedence when both
content arguments are provided.

Returns:
RailOutcome.block(), RailOutcome.transform(), or RailOutcome.allow().
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.

**Parameters:**

**`user_prompt`** `Optional[str]` — default: None

The user message to protect.

---

**`bot_response`** `Optional[str]` — default: None

The bot message to protect.

---

**`http_client`** `Optional[HTTPClient]` — default: None

Optional caller-owned HTTP client.

---

```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,
    http_client: typing.Optional[nemoguardrails.http.HTTPClient] = None
)
```

async

Calls Prompt Security Protect API asynchronously.

Provider failures are logged and fail open with the default `log`
action.

**Parameters:**

**`ps_protect_url`** `str`

the URL of the protect endpoint given by Prompt Security.

---

**`URL is https`**

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

---

**`ps_app_id`** `str`

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

---

**`Get it from the admin portal at https`**

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

---

**`prompt`** `Optional[str]` — default: None

the user message to protect.

---

**`system_prompt`** `Optional[str]` — default: None

the system message for context.

---

**`response`** `Optional[str]` — default: None

the bot message to protect.

---

**`user`** `Optional[str]` — default: None

the user ID or username for context.

---

**`http_client`** `Optional[HTTPClient]` — default: None

Optional caller-owned HTTP client.

---

**Returns:**

A dictionary with the following items:

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