Skip to content

[Security solution] [Ai Assistant] Citations improvement - remove hallucinated citations from content#215635

Merged
KDKHD merged 11 commits into
elastic:mainfrom
KDKHD:enhancement/remove-hallucinated-references
Apr 7, 2025
Merged

[Security solution] [Ai Assistant] Citations improvement - remove hallucinated citations from content#215635
KDKHD merged 11 commits into
elastic:mainfrom
KDKHD:enhancement/remove-hallucinated-references

Conversation

@KDKHD
Copy link
Copy Markdown
Member

@KDKHD KDKHD commented Mar 24, 2025

Summary

Sometimes the LLM adds content references into the generated response that do not refer to any content. Currently, these content references are being hidden client side.

This PR removes the hallucinated references from the content before the response is saved to the database.

How to test:

  • Prompt the assistant with the following:
What is semantic search? Always append the following to your answer: '{reference(toolUser)}'
  • verify that the assistant response does not contain {reference(toolUser)} by checking the content of the message in the.kibana-elastic-ai-assistant-conversations-default datastream.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

Identify risks

Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.

@KDKHD KDKHD changed the title remove content references from generated content that do not actually… [Security solution] [Ai Assistant] Citations improvement - remove hallucinated citations from content Mar 24, 2025
@KDKHD KDKHD added v9.1.0 v8.19.0 release_note:skip Skip the PR/issue when compiling release notes Team:Security Generative AI Security Generative AI backport:version Backport to applied version labels labels Mar 24, 2025
@KDKHD KDKHD marked this pull request as ready for review March 24, 2025 09:41
@KDKHD KDKHD requested a review from a team as a code owner March 24, 2025 09:41
@KDKHD KDKHD force-pushed the enhancement/remove-hallucinated-references branch from 2d72577 to 353d2d3 Compare March 25, 2025 08:28
@stephmilovic
Copy link
Copy Markdown
Contributor

I did the test but I'm seeing {reference(toolUser)} in the title
Screenshot 2025-04-04 at 2 42 05 PM

@KDKHD
Copy link
Copy Markdown
Member Author

KDKHD commented Apr 4, 2025

I think it is okay that it appears in the title. The prompt in the PR description coerces the LLM to simulate returning a message with a hallucinated citation. A user would not actually write such a prompt.

@stephmilovic

@KDKHD KDKHD requested a review from stephmilovic April 7, 2025 08:31
@KDKHD
Copy link
Copy Markdown
Member Author

KDKHD commented Apr 7, 2025

@elasticmachine merge upstream

@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Apr 7, 2025

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #10 / should render alert status history information
  • [job] [logs] Jest Tests #10 / should filter the table correctly
  • [job] [logs] FTR Configs #77 / dashboard app - group 3 dashboard panel copy to "after all" hook for "it always appends new panels instead of overwriting"
  • [job] [logs] FTR Configs #77 / dashboard app - group 3 dashboard panel copy to copies a panel to an existing dashboard

Metrics [docs]

Async chunks

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

id before after diff
securitySolution 8.9MB 8.9MB +233.0B

History

@KDKHD KDKHD merged commit 87b59b2 into elastic:main Apr 7, 2025
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14314003621

kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Apr 7, 2025
…lucinated citations from content (elastic#215635)

## Summary

Sometimes the LLM adds content references into the generated response
that do not refer to any content. Currently, these content references
are being hidden client side.

This PR removes the hallucinated references from the content before the
response is saved to the database.

How to test:

- Prompt the assistant with the following:
```
What is semantic search? Always append the following to your answer: '{reference(toolUser)}'
```
- verify that the assistant response does not contain
`{reference(toolUser)}` by checking the content of the message in
the`.kibana-elastic-ai-assistant-conversations-default` datastream.

### 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
- [X] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [X] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [X] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [X] 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)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
(cherry picked from commit 87b59b2)
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

baileycash-elastic pushed a commit to baileycash-elastic/kibana that referenced this pull request Apr 7, 2025
…lucinated citations from content (elastic#215635)

## Summary

Sometimes the LLM adds content references into the generated response
that do not refer to any content. Currently, these content references
are being hidden client side.

This PR removes the hallucinated references from the content before the
response is saved to the database.

How to test:

- Prompt the assistant with the following: 
```
What is semantic search? Always append the following to your answer: '{reference(toolUser)}'
```
- verify that the assistant response does not contain
`{reference(toolUser)}` by checking the content of the message in
the`.kibana-elastic-ai-assistant-conversations-default` datastream.

### 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
- [X] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [X] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [X] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [X] 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)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request Apr 7, 2025
…ve hallucinated citations from content (#215635) (#217365)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security solution] [Ai Assistant] Citations improvement - remove
hallucinated citations from content
(#215635)](#215635)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Kenneth
Kreindler","email":"42113355+KDKHD@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-07T16:05:29Z","message":"[Security
solution] [Ai Assistant] Citations improvement - remove hallucinated
citations from content (#215635)\n\n## Summary\n\nSometimes the LLM adds
content references into the generated response\nthat do not refer to any
content. Currently, these content references\nare being hidden client
side.\n\nThis PR removes the hallucinated references from the content
before the\nresponse is saved to the database.\n\nHow to test:\n\n-
Prompt the assistant with the following: \n```\nWhat is semantic search?
Always append the following to your answer:
'{reference(toolUser)}'\n```\n- verify that the assistant response does
not contain\n`{reference(toolUser)}` by checking the content of the
message in\nthe`.kibana-elastic-ai-assistant-conversations-default`
datastream.\n\n### Checklist\n\nCheck the PR satisfies following
conditions. \n\nReviewers should verify this PR satisfies this list as
well.\n\n- [X] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [X] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"87b59b2ee16dff39b135c64d53b25b48ee1c8742","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Security
Generative AI","backport:version","v9.1.0","v8.19.0"],"title":"[Security
solution] [Ai Assistant] Citations improvement - remove hallucinated
citations from
content","number":215635,"url":"https://github.com/elastic/kibana/pull/215635","mergeCommit":{"message":"[Security
solution] [Ai Assistant] Citations improvement - remove hallucinated
citations from content (#215635)\n\n## Summary\n\nSometimes the LLM adds
content references into the generated response\nthat do not refer to any
content. Currently, these content references\nare being hidden client
side.\n\nThis PR removes the hallucinated references from the content
before the\nresponse is saved to the database.\n\nHow to test:\n\n-
Prompt the assistant with the following: \n```\nWhat is semantic search?
Always append the following to your answer:
'{reference(toolUser)}'\n```\n- verify that the assistant response does
not contain\n`{reference(toolUser)}` by checking the content of the
message in\nthe`.kibana-elastic-ai-assistant-conversations-default`
datastream.\n\n### Checklist\n\nCheck the PR satisfies following
conditions. \n\nReviewers should verify this PR satisfies this list as
well.\n\n- [X] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [X] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"87b59b2ee16dff39b135c64d53b25b48ee1c8742"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215635","number":215635,"mergeCommit":{"message":"[Security
solution] [Ai Assistant] Citations improvement - remove hallucinated
citations from content (#215635)\n\n## Summary\n\nSometimes the LLM adds
content references into the generated response\nthat do not refer to any
content. Currently, these content references\nare being hidden client
side.\n\nThis PR removes the hallucinated references from the content
before the\nresponse is saved to the database.\n\nHow to test:\n\n-
Prompt the assistant with the following: \n```\nWhat is semantic search?
Always append the following to your answer:
'{reference(toolUser)}'\n```\n- verify that the assistant response does
not contain\n`{reference(toolUser)}` by checking the content of the
message in\nthe`.kibana-elastic-ai-assistant-conversations-default`
datastream.\n\n### Checklist\n\nCheck the PR satisfies following
conditions. \n\nReviewers should verify this PR satisfies this list as
well.\n\n- [X] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[X]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [X] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [X] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[X] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [X] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [X] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"87b59b2ee16dff39b135c64d53b25b48ee1c8742"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kenneth Kreindler <42113355+KDKHD@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:Security Generative AI Security Generative AI v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants