Skip to content

[8.19] [Obs AI Assistant] Add custom plugin for highlighting user and assistant responses when they have redacted entities (#224605)#225305

Merged
SrdjanLL merged 1 commit intoelastic:8.19from
SrdjanLL:backport/8.19/pr-224605
Jun 25, 2025
Merged

[8.19] [Obs AI Assistant] Add custom plugin for highlighting user and assistant responses when they have redacted entities (#224605)#225305
SrdjanLL merged 1 commit intoelastic:8.19from
SrdjanLL:backport/8.19/pr-224605

Conversation

@SrdjanLL
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 8.19:

Questions ?

Please refer to the Backport tool documentation

…ant responses when they have redacted entities (elastic#224605)

Closes: elastic/obs-ai-team#264

## Summary

Add custom plugin for highlighting user and assistant responses when
they have redacted entities:

- Custom plugin for `EuiMarkdownFormat` that highlights all content
wrapped inside anonymized node. The parsing plugin follows the approach
from [EUI
docs](https://eui.elastic.co/docs/components/editors-and-syntax/markdown/plugins/#putting-it-all-together-a-simple-chart-plugin)
and is used as follows:
   ```
!{anonymized{"entityClass":"<entity class>", "content": "<content"}}
    ```
- Highlighted content is currently rendered as `EuiCode`, but it can be
more sophisticated (i.e highlight differently depending on the entity
class).
- Allows using the same highlighting logic for messages from both `user`
and `assistant` roles.
- Currently **skipping highlighting inside the code blocks** - may
require customising the default plugins further.

Manually tested:
- Function calling seems to work as expected.
- Search results with PII are highlighted in the table.
- Custom regex matches are highlighted correctly.

### Testing instructions:
1. Used setup from elastic#216352 to set
up NER model locally.
2. Added to `kibana.dev.yml`:
```
uiSettings:
  overrides:
    'observability:aiAssistantAnonymizationRules': |
      [
        {
          "type": "regex",
          "pattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[A-Za-z]{2,}",
          "enabled": true,
          "entityClass": "EMAIL"
        },
        {
          "type": "regex",
          "pattern": "https?://[^\\s]+",
          "enabled": true,
          "entityClass": "URL"
        },
        {
          "type": "regex",
          "pattern": "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b",
          "enabled": true,
          "entityClass": "IP"
        },
        {
          "type": "ner",
          "enabled": true
        }
      ]
```
3. Used the assistant (see screenshots below)

### Screenshots
<img width="689" alt="image"
src="https://github.com/user-attachments/assets/d1f9bd57-7e76-43dc-88a6-d0be5fb15092"
/>

<img width="689" alt="image"
src="https://github.com/user-attachments/assets/ed63626b-b32d-45f8-9cf4-c575320d0dfc"
/>

<img width="689" alt="image"
src="https://github.com/user-attachments/assets/0b591158-9186-406a-aab3-e3be538216dc"
/>

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 05b4fdd)

# Conflicts:
#	x-pack/platform/packages/shared/kbn-ai-assistant/src/chat/chat_timeline.tsx
@SrdjanLL SrdjanLL requested a review from kibanamachine as a code owner June 25, 2025 14:06
@SrdjanLL SrdjanLL added the backport This PR is a backport of another PR label Jun 25, 2025
@SrdjanLL SrdjanLL enabled auto-merge (squash) June 25, 2025 14:06
@botelastic botelastic bot added the Team:Obs AI Assistant Observability AI Assistant label Jun 25, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant)

@SrdjanLL SrdjanLL merged commit aed5559 into elastic:8.19 Jun 25, 2025
10 checks passed
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
observabilityAIAssistant 109 110 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
observabilityAIAssistantApp 289.7KB 290.0KB +257.0B
searchAssistant 191.5KB 191.7KB +257.0B
total +514.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
observabilityAIAssistant 42.6KB 43.4KB +749.0B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR Team:Obs AI Assistant Observability AI Assistant

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants