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.
Parameters
| Name | Type | Description |
|---|---|---|
violations | string[] | The banned terms found in the answer, as the list writes them. |
message | string | The answer as it was, with the terms. |
payload | array | The request as the provider got it, keys in snake_case, with session_id and chatbot_settings. |
Example
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.