---
name: kimaai_chatbot_prompt
type: filter
since: 1.3.5
tier: free
feature: chatbot
area: chatbot
summary: Changes the visitor's message before the gate, the masking and the AI provider see it.
parameters:
  - name: prompt
    type: mixed
    description: The visitor's message as the request sent it, a string.
  - name: data
    type: array
    description: The request's JSON body.
  - name: request
    type: WP_REST_Request
    description: The REST request.
returns:
  type: mixed
  description: The message to use, a string.
surfaces: [chatbot, search]
---

# kimaai_chatbot_prompt

## When it fires

First thing in a chatbot request (`POST /wp-json/kimaai/v1/chatbot`), and in a search answer (`assistantSurface` `search`) before the answer cache is looked up. Nothing has run before it: after it come the masking of card numbers and IBANs, `kimaai_chatbot_gate`, the daily limit and the maximum message length, which counts the filtered message.

What the filter returns is the message from then on: the gate checks it, the provider gets it, and the chat history stores it. Return a string. In a search answer the cache key stays on the visitor's own query.

## Example

```php
add_filter(
  'kimaai_chatbot_prompt',
  function ($prompt, array $data, WP_REST_Request $request) {
    if (!is_string($prompt)) {
      return $prompt;
    }

    // One line, without the blank space a pasted text brings along.
    return trim((string) preg_replace('/\s+/u', ' ', $prompt));
  },
  10,
  3
);
```

## Related

- `kimaai_chatbot_gate`: blocks a message after this filter.
- `kimaai_chatbot_ai_payload`: changes the whole request to the provider, not only the message.
