Skip to content

feat: add Pangea AI Guard community integration #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions docs/user-guides/community/pangea.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Pangea AI Guard integration

The Pangea guardrail uses configurable detection policies (called *recipes*) from the [AI Guard service](https://pangea.cloud/docs/ai-guard/) to identify and mitigate risks in AI application traffic, including:

- Prompt injection attacks (with over 99% efficacy)
- 50+ types of PII and sensitive content, with support for custom patterns
- Toxicity, violence, self-harm, and other unwanted content
- Malicious links, IPs, and domains
- 100 spoken languages, with allowlist and denylist controls

All detections are logged in an audit trail for analysis, attribution, and incident response.
You can also configure webhooks to trigger alerts for specific detection types.

The following environment variable is required to use the Pangea AI Guard integration:

- `PANGEA_API_TOKEN`: Pangea API token with access to the AI Guard service.

You can also optionally set:

- `PANGEA_BASE_URL_TEMPLATE`: Template for constructing the base URL for API requests. The `{SERVICE_NAME}` placeholder will be replaced with the service name slug.
Defaults to `https://ai-guard.aws.us.pangea.cloud` for Pangea's hosted (SaaS) deployment.

## Setup

Colang v1:

```yaml
# config.yml

rails:
config:
pangea:
input:
recipe: pangea_prompt_guard
output:
recipe: pangea_llm_response_guard

input:
flows:
- pangea ai guard input

output:
flows:
- pangea ai guard output
```

Colang v2:

```yaml
# config.yml

colang_version: "2.x"

rails:
config:
pangea:
input:
recipe: pangea_prompt_guard
output:
recipe: pangea_llm_response_guard
```

```
# rails.co

import guardrails
import nemoguardrails.library.pangea

flow input rails $input_text
pangea ai guard input

flow output rails $output_text
pangea ai guard output
```

## Next steps

- Explore example configurations for integrating Pangea AI Guard with your preferred Colang version:
- [Pangea AI Guard for NeMo Guardrails v1](https://github.com/NVIDIA/NeMo-Guardrails/tree/develop/examples/configs/pangea)
- [Pangea AI Guard for NeMo Guardrails v2](https://github.com/NVIDIA/NeMo-Guardrails/tree/develop/examples/configs/pangea_v2)
- [Pangea AI Guard without LLM (guardrails only)](https://github.com/NVIDIA/NeMo-Guardrails/tree/develop/examples/configs/pangea_v2_no_llm) – Use this setup to evaluate AI Guard’s detection and response capabilities independently.
- Adjust your detection policies to fit your application’s risk profile. See the [AI Guard Recipes](https://pangea.cloud/docs/ai-guard/recipes) documentation for configuration details.
- Enable [AI Guard webhooks](https://pangea.cloud/docs/ai-guard/recipes#add-webhooks-to-detectors) to receive real-time alerts for detections in your NeMo Guardrails-powered application.
- Monitor and analyze detection activity in the [AI Guard Activity Log](https://pangea.cloud/docs/ai-guard/activity-log) for auditing and attribution.
- Learn more about [AI Guard Deployment Options](https://pangea.cloud/docs/deployment-models/) to understand how and where AI Guard can run to protect your AI applications.
21 changes: 21 additions & 0 deletions docs/user-guides/guardrails-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NeMo Guardrails comes with a library of built-in guardrails that you can easily
- [Private AI PII detection](#private-ai-pii-detection)
- [Fiddler Guardrails for Safety and Hallucination Detection](#fiddler-guardrails-for-safety-and-hallucination-detection)
- [Prompt Security Protection](#prompt-security-protection)
- [Pangea AI Guard](#pangea-ai-guard)
- OpenAI Moderation API - *[COMING SOON]*

4. Other
Expand Down Expand Up @@ -866,6 +867,26 @@ rails:

For more details, check out the [Prompt Security Integration](./community/prompt-security.md) page.

### Pangea AI Guard

NeMo Guardrails supports using [Pangea AI Guard](https://pangea.cloud/services/ai-guard/) for protecting data and
interactions with LLMs within AI-powered applications.

#### Example usage

```yaml
rails:
input:
flows:
- pangea ai guard input

output:
flows:
- pangea ai guard output
```

For more details, check out the [Pangea AI Guard Integration](./community/pangea.md) page.

## Other

### Jailbreak Detection
Expand Down
1 change: 1 addition & 0 deletions docs/user-guides/llm-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ If you want to use an LLM and you cannot see a prompt in the [prompts folder](ht
| Patronus Evaluate API _(LLM independent)_ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Fiddler Fast Faitfhulness Hallucination Detection _(LLM independent)_ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔
| Fiddler Fast Safety & Jailbreak Detection _(LLM independent)_ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Pangea AI Guard integration _(LLM independent)_ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |

Table legend:

Expand Down
14 changes: 14 additions & 0 deletions examples/configs/pangea/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Pangea Example

This example demonstrates how to integrate with the [Pangea AI Guard](https://pangea.cloud/services/ai-guard/) API for protecting data and interactions with LLMs within AI-powered applications

To test this configuration you can use the CLI Chat by running the following command from the `examples/configs/pangea` directory:

```bash
poetry run nemoguardrails chat --config=.
```

Documentation:

- [Full Pangea integration guide](../../../docs/user-guides/community/pangea.md)
- [Configuration options and setup instructions](../../../docs/user-guides/community/pangea.md#setup)
24 changes: 24 additions & 0 deletions examples/configs/pangea/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
models:
- type: main
engine: openai
model: gpt-4o-mini

instructions:
- type: general
content: |
You are a helpful assistant.

rails:
config:
pangea:
input:
recipe: pangea_prompt_guard
output:
recipe: pangea_llm_response_guard

input:
flows:
- pangea ai guard input
output:
flows:
- pangea ai guard output
14 changes: 14 additions & 0 deletions examples/configs/pangea_v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Pangea Example

This example demonstrates how to integrate with the [Pangea AI Guard](https://pangea.cloud/services/ai-guard/) API for protecting data and interactions with LLMs within AI-powered applications

To test this configuration you can use the CLI Chat by running the following command from the `examples/configs/pangea_v2` directory:

```bash
poetry run nemoguardrails chat --config=.
```

Documentation:

- [Full Pangea integration guide](../../../docs/user-guides/community/pangea.md)
- [Configuration options and setup instructions](../../../docs/user-guides/community/pangea.md#setup)
19 changes: 19 additions & 0 deletions examples/configs/pangea_v2/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
colang_version: "2.x"

models:
- type: main
engine: openai
model: gpt-4o-mini

instructions:
- type: general
content: |
You are a helpful assistant.

rails:
config:
pangea:
input:
recipe: pangea_prompt_guard
output:
recipe: pangea_llm_response_guard
5 changes: 5 additions & 0 deletions examples/configs/pangea_v2/main.co
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import core
import llm

flow main
activate llm continuation
8 changes: 8 additions & 0 deletions examples/configs/pangea_v2/rails.co
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import guardrails
import nemoguardrails.library.pangea

flow input rails $input_text
pangea ai guard input

flow output rails $output_text
pangea ai guard output
12 changes: 12 additions & 0 deletions examples/configs/pangea_v2_no_llm/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
colang_version: "2.x"

# No models section - guardrails only mode
# No LLM is required since we're only using Pangea APIs

rails:
config:
pangea:
input:
recipe: pangea_prompt_guard
output:
recipe: pangea_llm_response_guard
12 changes: 12 additions & 0 deletions examples/configs/pangea_v2_no_llm/main.co
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import core

flow main
activate message handler

# Allow continuation after blocked messages in guardrails only mode
flow message handler
when user said something
global $user_message
# At this point, $user_message contains the processed value from input rails
bot say "Processed message: {$user_message}"
activate message handler # Reactivate for next message
8 changes: 8 additions & 0 deletions examples/configs/pangea_v2_no_llm/rails.co
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import guardrails
import nemoguardrails.library.pangea

flow input rails $input_text
pangea ai guard input

flow output rails $output_text
pangea ai guard output
14 changes: 14 additions & 0 deletions nemoguardrails/library/pangea/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading