---
name: kimaai_chatbot_guardrails_violation
type: action
since: 1.5.4
tier: free
feature: guardrails
area: chatbot
summary: Fires when an answer contains a term of the banned terms list, before the term is masked.
parameters:
  - name: violations
    type: string[]
    description: The banned terms found in the answer, as the list writes them.
  - name: message
    type: string
    description: The answer as it was, with the terms.
  - name: payload
    type: array
    description: The request as the provider got it, keys in snake_case, with session_id and chatbot_settings.
surfaces: [chatbot, search]
---

# kimaai_chatbot_guardrails_violation

## When it fires

When the output guardrails are on and an answer contains one or more of the banned terms (case does not matter). The guardrails run on `kimaai_chatbot_final_message` at priority 30, after the citations, so they check the whole text. The action fires before each term is replaced with `███`; the visitor and the chat history only ever get the masked answer. While the guardrails are on and terms are set, answers do not stream, so a term never reaches the visitor first.

The action cannot change the answer: use `kimaai_chatbot_final_message` for that.

## Example

```php
add_action(
  'kimaai_chatbot_guardrails_violation',
  function (array $violations, string $message, array $payload): void {
    wp_mail(
      get_option('admin_email'),
      'The chatbot used a banned term',
      sprintf("Terms: %s\nThe visitor saw the answer with the terms masked.", implode(', ', $violations))
    );
  },
  10,
  3
);
```

## Related

- `kimaai_chatbot_final_message`: the answer text the guardrails check.
- `kimaai_chatbot_ungrounded_answer`: fires when an answer is not supported by the sources.
