> This page is for version v0.25.0.
> For other versions, use one of these documentation indexes:
> - Latest (default): https://docs.nvidia.com/nemo/guardrails/latest/llms.txt
> - v0.25.0: https://docs.nvidia.com/nemo/guardrails/v0.25.0/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.

# ActiveFence Integration

NeMo Guardrails supports using the [ActiveFence ActiveScore API](https://docs.activefence.com/index.html) as an input and output rail out-of-the-box (you need to have the `ACTIVEFENCE_API_KEY` environment variable set).

```yaml
rails:
  input:
    flows:
      # The simplified version
      - activefence moderation on input

      # The detailed version with individual risk scores
      # - activefence moderation on input detailed
```

The `activefence moderation on input` flow blocks when the maximum risk score exceeds `0.7`. The `activefence moderation on input detailed` flow uses individual thresholds per category of violation.

The action returns a [RailOutcome](/nemo/guardrails/v0.25.0/configure-guardrails/actions/rail-outcomes) whose `metadata` contains the `max_risk_score` and the per-category `violations` scores. To customize the scores, overwrite the [default Colang 1.0 flows](https://github.com/NVIDIA-NeMo/Guardrails/tree/develop/nemoguardrails/library/activefence/flows.v1.co) in your config. For example, to change the threshold for `activefence moderation on input` to `0.85`, add the following flow to your config:

```text
define subflow activefence moderation on input
  """Guardrail based on the maximum risk score."""
  $result = execute call_activefence_api(text=$user_message)

  if $result.metadata["max_risk_score"] > 0.85
    bot refuse to respond
    stop
```

The condition in your flow replaces the built-in decision, so `$result.is_blocked` is not checked.

ActiveFence's ActiveScore API gives flexibility in controlling the behavior of various supported violations individually. To leverage that, you can use the `violations` dictionary in the outcome metadata to set different thresholds for different violations. Below is an example of one such input moderation flow, which you add to `rails.input.flows` in place of the built-in flow. It checks only the conditions you write, so add one for each category you want to block:

```text
define flow activefence input moderation detailed
  $result = execute call_activefence_api(text=$user_message)

  if $result.metadata["violations"].get("abusive_or_harmful.hate_speech", 0) > 0.8
    bot inform cannot engage in abusive or harmful behavior
    stop

define bot inform cannot engage in abusive or harmful behavior
  "I will not engage in any abusive or harmful behavior."
```