---
title: AI Defense (NeMo Guardrail)
type: guardrail
provider: nvidia
category: safety
source: 'https://github.com/NVIDIA-NeMo/Guardrails'
license: Apache-2.0
tags:
  - guardrail
  - nemo
  - rails
  - colang
dateAdded: '2026-01-24'
featured: false
origin: official
language: en
description: >-
  INPUT RAILS flow ai defense inspect prompt $input_text """Check if the prompt
  is safe according to AI Defense.""" $result = await AiDefenseInspectActi
---

```coffee
# INPUT RAILS

flow ai defense inspect prompt $input_text
  """Check if the prompt is safe according to AI Defense."""
  $result = await AiDefenseInspectAction(user_prompt=$input_text)
  if $result["is_blocked"]
    if $system.config.enable_rails_exceptions
      send AIDefenseRailException(message="Prompt not allowed. The prompt was blocked by the 'ai defense inspect prompt' flow.")
    else
      bot refuse to respond
    abort


# OUTPUT RAILS

flow ai defense inspect response $output_text
  """Check if the response is safe according to AI Defense."""
  $result = await AiDefenseInspectAction(bot_response=$output_text)
  if $result["is_blocked"]
    if $system.config.enable_rails_exceptions
      send AIDefenseRailException(message="Response not allowed. The response was blocked by the 'ai defense inspect response' flow.")
    else
      bot refuse to respond
    abort
```
