-
Notifications
You must be signed in to change notification settings - Fork 549
feat: Add Trend Micro Vision One AI Application Security community integration #1355
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
Merged
Pouyanpi
merged 4 commits into
NVIDIA-NeMo:develop
from
trend-willem-gooderham:feature/trend-ai-guard
Sep 22, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6155e38
feat: Add Trend Micro AI Guard community integration
trend-willem-gooderham c8fd3f6
fixup: Address CoPilot comments
trend-willem-gooderham 3412335
fixup: Address PR Comments
trend-willem-gooderham 92c444f
Fixup: Address additional PR comments
trend-willem-gooderham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Trend Micro Vision One AI Application Security | ||
|
||
Trend Micro Vision One [AI Application Security's](https://docs.trendmicro.com/en-us/documentation/article/trend-vision-one-ai-scanner-ai-guard) AI Guard feature uses a configurable policy to identify risks in AI Applications, such as: | ||
|
||
- Prompt injection attacks | ||
- Toxicity, violent, and other harmful content | ||
- Sensitive Data | ||
erickgalinkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
## Setup | ||
trend-willem-gooderham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. Create a new [Vision One API Key](https://docs.trendmicro.com/en-us/documentation/article/trend-vision-one-platform-api-keys) with permissions to Call Detection API | ||
2. See the [AI Guard Integration Guide](https://docs.trendmicro.com/en-us/documentation/article/trend-vision-one-platform-api-keys) for details around creating your policy | ||
|
||
[Colang v1](../../../examples/configs/trend_micro/): | ||
|
||
```yaml | ||
# config.yml | ||
|
||
rails: | ||
config: | ||
trend_micro: | ||
v1_url: "https://api.xdr.trendmicro.com/beta/aiSecurity/guard" # Replace this with your AI Guard URL | ||
api_key_env_var: "V1_API_KEY" | ||
input: | ||
flows: | ||
- trend ai guard input | ||
|
||
output: | ||
flows: | ||
- trend ai guard output | ||
``` | ||
[Colang v2](../../../examples/configs/trend_micro_v2/): | ||
```yaml | ||
# config.yml | ||
colang_version: "2.x" | ||
rails: | ||
config: | ||
trend_micro: | ||
v1_url: "https://api.xdr.trendmicro.com/beta/aiSecurity/guard" # Replace this with your AI Guard URL | ||
api_key_env_var: "V1_API_KEY" | ||
``` | ||
``` | ||
# rails.co | ||
|
||
import guardrails | ||
import nemoguardrails.library.trend_micro | ||
|
||
flow input rails $input_text | ||
trend ai guard $input_text | ||
|
||
flow output rails $output_text | ||
trend ai guard $output_text | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Trend Micro Vision One AI Application Security Example | ||
|
||
This example demonstrates how to integrate with the Trend Micro Vision One 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/trend_micro` directory: | ||
|
||
```bash | ||
poetry run nemoguardrails chat --config=. | ||
``` | ||
|
||
Documentation: | ||
|
||
- [Configuration options and setup instructions](../../../docs/user-guides/community/trend-micro.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
enable_rails_exceptions: True | ||
|
||
models: | ||
- type: main | ||
engine: openai | ||
model: gpt-4o-mini | ||
|
||
instructions: | ||
- type: general | ||
content: | | ||
You are a helpful assistant. | ||
|
||
rails: | ||
config: | ||
trend_micro: | ||
api_key_env_var: "V1_API_KEY" | ||
input: | ||
flows: | ||
- trend ai guard input | ||
output: | ||
flows: | ||
- trend ai guard output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Trend Micro Vision One AI Application Security Example | ||
|
||
This example demonstrates how to integrate with the Trend Micro Vision One API 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/trend_micro_v2` directory: | ||
|
||
```bash | ||
poetry run nemoguardrails chat --config=. | ||
``` | ||
|
||
Documentation: | ||
|
||
- [Configuration options and setup instructions](../../../docs/user-guides/community/trend-micro.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
colang_version: "2.x" | ||
|
||
enable_rails_exceptions: True | ||
|
||
rails: | ||
config: | ||
trend_micro: | ||
api_key_env_var: "V1_API_KEY" | ||
|
||
models: | ||
- type: main | ||
engine: openai | ||
model: gpt-4o-mini | ||
|
||
instructions: | ||
- type: general | ||
content: | | ||
You are a helpful assistant. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import core | ||
import llm | ||
|
||
flow main | ||
activate llm continuation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import guardrails | ||
import nemoguardrails.library.trend_micro | ||
|
||
flow input rails $input_text | ||
trend ai guard input $input_text | ||
|
||
flow output rails $output_text | ||
trend ai guard output $output_text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# 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. | ||
|
||
import logging | ||
from typing import Literal, Optional | ||
|
||
import httpx | ||
from pydantic import BaseModel, Field | ||
from pydantic import field_validator as validator | ||
from pydantic import model_validator | ||
from pydantic_core import to_json | ||
from typing_extensions import cast | ||
|
||
from nemoguardrails.actions import action | ||
from nemoguardrails.rails.llm.config import RailsConfig, TrendMicroRailConfig | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class Guard(BaseModel): | ||
""" | ||
Represents a guard entity with a single string attribute. | ||
|
||
Attributes: | ||
guard (str): The input text for guard analysis. | ||
""" | ||
|
||
guard: str | ||
|
||
|
||
class GuardResult(BaseModel): | ||
""" | ||
Represents the result of a guard analysis, specifying the action to take and the reason. | ||
|
||
Attributes: | ||
action (Literal["Block", "Allow"]): The action to take based on guard analysis. | ||
Must be either "Block" or "Allow". | ||
reason (str): Explanation for the chosen action. Must be a non-empty string. | ||
""" | ||
|
||
action: Literal["Block", "Allow"] = Field( | ||
..., description="Action to take based on " "guard analysis" | ||
) | ||
reason: str = Field(..., min_length=1, description="Explanation for the action") | ||
blocked: bool = Field( | ||
default=False, description="True if action is 'Block', else False" | ||
) | ||
|
||
@validator("action") | ||
def validate_action(cls, v): | ||
log.error(f"Validating action: {v}") | ||
if v not in ["Block", "Allow"]: | ||
return "Allow" | ||
return v | ||
|
||
@model_validator(mode="before") | ||
def set_blocked(cls, values): | ||
a = values.get("action") | ||
values["blocked"] = a.lower() == "block" | ||
return values | ||
|
||
|
||
def get_config(config: RailsConfig) -> TrendMicroRailConfig: | ||
""" | ||
Retrieves the TrendMicroRailConfig from the provided RailsConfig object. | ||
|
||
Args: | ||
config (RailsConfig): The Rails configuration object containing possible | ||
Trend Micro settings. | ||
|
||
Returns: | ||
TrendMicroRailConfig: The Trend Micro configuration, either from the provided | ||
config or a default instance. | ||
""" | ||
if ( | ||
not hasattr(config.rails.config, "trend_micro") | ||
or config.rails.config.trend_micro is None | ||
): | ||
return TrendMicroRailConfig() | ||
|
||
return cast(TrendMicroRailConfig, config.rails.config.trend_micro) | ||
|
||
|
||
def trend_ai_guard_mapping(result: GuardResult) -> bool: | ||
"""Convert Trend Micro result to boolean for flow logic.""" | ||
return result.action.lower() == "block" | ||
|
||
|
||
@action(is_system_action=True, output_mapping=trend_ai_guard_mapping) | ||
async def trend_ai_guard(config: RailsConfig, text: Optional[str] = None): | ||
""" | ||
Custom action to invoke the Trend Ai Guard | ||
""" | ||
|
||
trend_config = get_config(config) | ||
|
||
# No checks required since default is set in TrendMicroRailConfig | ||
v1_url = trend_config.v1_url | ||
|
||
v1_api_key = trend_config.get_api_key() | ||
if not v1_api_key: | ||
log.error("Trend Micro Vision One API Key not found") | ||
return GuardResult( | ||
action="Block", | ||
reason="Trend Micro Vision One API Key not found", | ||
) | ||
|
||
async with httpx.AsyncClient() as client: | ||
data = Guard(guard=text).model_dump() | ||
|
||
response = await client.post( | ||
v1_url, | ||
content=to_json(data), | ||
headers={ | ||
"Authorization": f"Bearer {v1_api_key}", | ||
"Content-Type": "application/json", | ||
}, | ||
) | ||
|
||
try: | ||
response.raise_for_status() | ||
guard_result = GuardResult(**response.json()) | ||
log.debug("Trend Micro AI Guard Result: %s", guard_result) | ||
except httpx.HTTPStatusError as e: | ||
log.error("Error calling Trend Micro AI Guard API: %s", e) | ||
return GuardResult( | ||
action="Allow", | ||
reason="An error occurred while calling the Trend Micro AI Guard API.", | ||
) | ||
return guard_result |
Pouyanpi marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# INPUT AND/OR OUTPUT RAIL | ||
flow trend ai guard input $text | ||
$result = await TrendAiGuardAction(text=$text) | ||
|
||
if $result.blocked # Fails open if AI Guard service has an error | ||
if $system.config.enable_rails_exceptions | ||
send TrendAiGuardRailException(message="Blocked by the 'trend ai guard input' flow: " + $result.reason) | ||
else | ||
bot refuse to respond | ||
abort | ||
|
||
|
||
# OUTPUT RAIL | ||
flow trend ai guard output $text | ||
$result = await TrendAiGuardAction(text=$text) | ||
|
||
if $result.blocked # Fails open if AI Guard service has an error | ||
if $system.config.enable_rails_exceptions | ||
send TrendAiGuardRailException(message="Blocked by the 'trend ai guard output' flow: " + $result.reason) | ||
else | ||
bot refuse to respond | ||
abort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# INPUT RAIL | ||
define subflow trend ai guard input | ||
$result = execute trend_ai_guard(text=$user_message) | ||
|
||
if $result.blocked # Fails open if AI Guard service has an error | ||
if $config.enable_rails_exceptions | ||
$msg = "Blocked by the 'trend ai guard input' flow: " + $result.reason | ||
create event TrendAiGuardRailException(message=$msg) | ||
else | ||
bot refuse to respond | ||
stop | ||
|
||
# OUTPUT RAIL | ||
define subflow trend ai guard output | ||
$result = execute trend_ai_guard(text=$bot_message) | ||
|
||
if $result.blocked # Fails open if AI Guard service has an error | ||
if $config.enable_rails_exceptions | ||
$msg = "Blocked by the 'trend ai guard output' flow: " + $result.reason | ||
create event TrendAiGuardRailException(message=$msg) | ||
else | ||
bot refuse to respond | ||
stop |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.