|
| 1 | +# Cisco AI Defense Integration |
| 2 | + |
| 3 | +[Cisco AI Defense](https://www.cisco.com/site/us/en/products/security/ai-defense/index.html?utm_medium=github&utm_campaign=nemo-guardrails) allows you to protect LLM interactions. This integration enables NeMo Guardrails to use Cisco AI Defense to protect input and output flows. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The diagram below shows how Cisco AI Defense integrates with the NeMo Guardrails flow to provide comprehensive protection at both input and output stages: |
| 8 | + |
| 9 | +```{image} ../../_static/images/guardrails_flow_ai_defense.png |
| 10 | +:alt: "High-level flow through programmable guardrails including AI Defense integration, showing how Cisco AI Defense provides privacy, safety, and security inspection for both input and output rails" |
| 11 | +:align: center |
| 12 | +``` |
| 13 | + |
| 14 | +You'll need to set the following environment variables to work with Cisco AI Defense: |
| 15 | + |
| 16 | +1. AI_DEFENSE_API_ENDPOINT - This is the URL for the Cisco AI Defense inspection API endpoint. This will look like https://[REGION].api.inspect.aidefense.security.cisco.com/api/v1/inspect/chat where REGION is us, ap, eu, etc. |
| 17 | +2. AI_DEFENSE_API_KEY - This is the API key for Cisco AI Defense. It is used to authenticate the API request. It can be generated from the [Cisco Security Cloud Control UI](https://security.cisco.com) |
| 18 | + |
| 19 | +## Setup |
| 20 | + |
| 21 | +1. Ensure that you have access to the [Cisco AI Defense endpoints](https://developer.cisco.com/docs/ai-defense/) (SaaS or in your private deployment) |
| 22 | +2. Set the required environment variables: `AI_DEFENSE_API_ENDPOINT` and `AI_DEFENSE_API_KEY` |
| 23 | + |
| 24 | +### For Colang 1.0 |
| 25 | + |
| 26 | +Enable Cisco AI Defense flows in your `config.yml` file: |
| 27 | + |
| 28 | +```yaml |
| 29 | +rails: |
| 30 | + config: |
| 31 | + ai_defense: |
| 32 | + timeout: 30.0 |
| 33 | + fail_open: false |
| 34 | + |
| 35 | + input: |
| 36 | + flows: |
| 37 | + - ai defense inspect prompt |
| 38 | + |
| 39 | + output: |
| 40 | + flows: |
| 41 | + - ai defense inspect response |
| 42 | +``` |
| 43 | +
|
| 44 | +### For Colang 2.x |
| 45 | +
|
| 46 | +You can set configuration options in your `config.yml`: |
| 47 | + |
| 48 | +```yaml |
| 49 | +# config.yml |
| 50 | +colang_version: "2.x" |
| 51 | +
|
| 52 | +rails: |
| 53 | + config: |
| 54 | + ai_defense: |
| 55 | + timeout: 30.0 |
| 56 | + fail_open: false |
| 57 | +``` |
| 58 | + |
| 59 | +Example `rails.co` file: |
| 60 | + |
| 61 | +```colang |
| 62 | +import guardrails |
| 63 | +import nemoguardrails.library.ai_defense |
| 64 | +
|
| 65 | +flow input rails $input_text |
| 66 | + """Check user utterances before they get further processed.""" |
| 67 | + ai defense inspect prompt $input_text |
| 68 | +
|
| 69 | +flow output rails $output_text |
| 70 | + """Check bot responses before sending them to the user.""" |
| 71 | + ai defense inspect response $output_text |
| 72 | +``` |
| 73 | + |
| 74 | +### Configuration Options |
| 75 | + |
| 76 | +The AI Defense integration supports the following configuration options under `rails.config.ai_defense`: |
| 77 | + |
| 78 | +- **`timeout`** (float, default: 30.0): Timeout in seconds for API requests to the AI Defense service. |
| 79 | +- **`fail_open`** (boolean, default: false): Determines the behavior when AI Defense API calls fail: |
| 80 | + - `false` (fail closed): Block content when API calls fail or return malformed responses |
| 81 | + - `true` (fail open): Allow content when API calls fail or return malformed responses |
| 82 | + |
| 83 | +**Note**: Configuration validation failures (missing API key or endpoint) will always block content regardless of the `fail_open` setting. |
| 84 | + |
| 85 | +## Usage |
| 86 | + |
| 87 | +Once configured, the Cisco AI Defense integration will automatically: |
| 88 | + |
| 89 | +1. Protect prompts before they are processed by the LLM. |
| 90 | +2. Protect LLM outputs before they are sent back to the user. |
| 91 | + |
| 92 | +The `ai_defense_inspect` action in `nemoguardrails/library/ai_defense/actions.py` handles the protection process. |
| 93 | + |
| 94 | +## Error Handling |
| 95 | + |
| 96 | +The AI Defense integration provides configurable error handling through the `fail_open` setting: |
| 97 | + |
| 98 | +- **Fail Closed (default)**: When `fail_open: false`, API failures and malformed responses will block the content (conservative approach) |
| 99 | +- **Fail Open**: When `fail_open: true`, API failures and malformed responses will allow the content to proceed |
| 100 | + |
| 101 | +This allows you to choose between security (fail closed) and availability (fail open) based on your requirements. |
| 102 | + |
| 103 | +### Error Scenarios |
| 104 | + |
| 105 | +1. **API Failures** (network errors, timeouts, HTTP errors): Behavior determined by `fail_open` setting |
| 106 | +2. **Malformed Responses** (missing required fields): Behavior determined by `fail_open` setting |
| 107 | +3. **Configuration Errors** (missing API key/endpoint): Always fail closed regardless of `fail_open` setting |
| 108 | + |
| 109 | +## Notes |
| 110 | + |
| 111 | +For more information on Cisco AI Defense capabilities and configuration, please refer to the [Cisco AI Defense documentation](https://securitydocs.cisco.com/docs/scc/admin/108321.dita?utm_medium=github&utm_campaign=nemo-guardrails). |
0 commit comments