> ## Documentation Index
> Fetch the complete documentation index at: https://docs.poly.ai/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.poly.ai/feedback

```json
{
  "path": "/response-control/stop-keywords",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# Stop keywords

> Block or log specific phrases in agent responses.

When a response matches a stop keyword pattern, the system halts the response and logs the occurrence. Use stop keywords to catch sensitive content, remove unnecessary preambles, or enforce brand adherence.

## Stop keyword fields

| Field                  | Type      | Description                                                                                                                             |
| ---------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **Title**              | String    | Unique name for the stop keyword rule (max 100 characters)                                                                              |
| **Description**        | String    | Optional note clarifying the keyword's purpose                                                                                          |
| **Regular Expression** | String    | One or more regex patterns that identify phrases to control                                                                             |
| **Say Phrases**        | Boolean   | `TRUE` – the agent speaks the text up to the matched phrase, then stops. `FALSE` – the agent is interrupted before speaking the phrase. |
| **Language**           | String    | Which language this rule applies to. Defaults to "All languages". Only visible for multilingual agents.                                 |
| **Function**           | Reference | Optional – a [function](/tools/introduction) to call when the phrase is detected                                                        |

<Warning>
  When a function is triggered by a stop keyword, **caller input and LLM parameters are not passed** to the function. The function runs without conversation context, so it should return a static response or handle the absence of context gracefully.
</Warning>

## Creating a stop keyword

<Tabs>
  <Tab title="1. Create a function">
    <img src="https://mintcdn.com/polyai/Qu880HppNqT19Eyr/images/response-control/stop-keywords-function.png?fit=max&auto=format&n=Qu880HppNqT19Eyr&q=85&s=e5ab39a03aa85dbc44cb2d63b93c2be9" alt="Creating a stop keyword function" width="1852" height="1046" data-path="images/response-control/stop-keywords-function.png" />

    Go to **[Build > Tools](/tools/introduction)** to define a custom function for handling stop keywords.

    **Example setup**:

    * **Name**: restricted\_phrase
    * **Description**: Respond when stop keywords are detected.
    * **Type**: String
    * **Function definition**:

    ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    def restricted_phrase(conv: Conversation):
        return "I can only help with questions about our products and services."
    ```
  </Tab>

  <Tab title="2. Configure the keyword">
    <img src="https://mintcdn.com/polyai/Qu880HppNqT19Eyr/images/response-control/stop-keywords-response-control.png?fit=max&auto=format&n=Qu880HppNqT19Eyr&q=85&s=3e7b6598a020ef275771223dc67d526f" alt="Stop keyword configuration" width="1710" height="1084" data-path="images/response-control/stop-keywords-response-control.png" />

    Next, go to the **Response Controls** section and add a new stop keyword.

    **Setup details**:

    * **ID**: restricted\_phrase
    * **Description**: Restrict responses containing specific phrases.
    * **Regular Expression**: `\brestricted_term\b`
    * **Say Phrases**: `TRUE` (to halt responses when detected).
    * **Action**: Link to the `restricted_phrase` function.
  </Tab>

  <Tab title="3. Test">
    <img src="https://mintcdn.com/polyai/Qu880HppNqT19Eyr/images/response-control/stop-keywords-test.png?fit=max&auto=format&n=Qu880HppNqT19Eyr&q=85&s=de89e194591794bac93c7cc42c03dd0c" alt="Testing stop keyword" width="2482" height="1568" data-path="images/response-control/stop-keywords-test.png" />

    Go to the **Webchat** testing panel to validate your setup.

    **Steps**:

    1. Type a message containing the word "Ashmolean."
    2. Observe the agent's response: "The detected phrase is restricted. Please adjust your input."
    3. Confirm that the agent halts any further response generation.

    **Expected result**:
    The agent successfully identifies the stop keyword, triggers the linked function, and stops further dialogue.
  </Tab>
</Tabs>

## Common use cases

<AccordionGroup>
  <Accordion title="Safety compliance" icon="shield-halved">
    Prevent offensive or harmful language in user interactions.

    | Field           | Value                                  |
    | --------------- | -------------------------------------- |
    | **ID**          | `stop_inappropriate`                   |
    | **Regex**       | `\b(offensiveWord1\|offensiveWord2)\b` |
    | **Say Phrases** | `TRUE`                                 |
  </Accordion>

  <Accordion title="Remove LLM preambles" icon="scissors">
    LLMs often add unnecessary meta-explanations before executing an action. Stop keywords cut these off instantly.

    **Before:** "Let's start by gathering some information. Please hold on while I check your cancellation options. Here are your cancellation options."

    **After:** "Here are your cancellation options."

    <Steps>
      <Step title="Add the stop keyword">
        Go to **Channels > Voice > Response control** and click **Add Phrase**:

        | Field           | Value                                             |
        | --------------- | ------------------------------------------------- |
        | **ID**          | `flow_redundancy_cutoff`                          |
        | **Regex**       | `\b(let's start\|please hold on\|let me check)\b` |
        | **Say Phrases** | `TRUE`                                            |
      </Step>

      <Step title="Optional: redirect to a function">
        Trigger a function to replace the blocked phrase with a cleaner response:

        ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
        def flow_redundancy_cutoff(conv: Conversation):
            return "Here are your options."
        ```
      </Step>

      <Step title="Test">
        Save and test the agent's responses in sandbox.
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Brand adherence" icon="badge-check">
    Block responses with phrases outside approved messaging. Log matches for review in the [Analytics Dashboard](/analytics/dashboards/introduction).
  </Accordion>
</AccordionGroup>

<Tip>
  Use regex for complex patterns. See [regex101.com](https://regex101.com/) for a testing tool.
</Tip>

## Related pages

<CardGroup cols={2}>
  <Card title="Pronunciations" icon="volume-high" href="/response-control/pronunciations">
    Control how your agent pronounces specific terms.
  </Card>

  <Card title="Translations" icon="language" href="/response-control/translations">
    Override auto-translated content for multilingual agents.
  </Card>
</CardGroup>
