Skip to content

[O11y AI Assistant] Correct quotes in ES|QL queries for function arguments #217680

Merged
darnautov merged 5 commits intoelastic:mainfrom
darnautov:ml-216445-fix-field-escaping
Apr 30, 2025
Merged

[O11y AI Assistant] Correct quotes in ES|QL queries for function arguments #217680
darnautov merged 5 commits intoelastic:mainfrom
darnautov:ml-216445-fix-field-escaping

Conversation

@darnautov
Copy link
Contributor

@darnautov darnautov commented Apr 9, 2025

Summary

Fixes #216445

Related issue #198942

An attempt to fix incorrect quotes for field arguments inserted by LLMs. The solution isn’t perfect, but it’s the best we could come up with for now. Since ES|QL functions can have varying numbers of arguments, with different orders and types, we use a regex to scan the query string, look up the function definition, and replace quotes only when the argument is identified as a field.

Checklist

@darnautov
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

merge conflict between base and head

@darnautov darnautov marked this pull request as ready for review April 25, 2025 13:29
@darnautov darnautov requested review from a team as code owners April 25, 2025 13:29
@darnautov darnautov self-assigned this Apr 25, 2025
@darnautov darnautov added Team:Obs AI Assistant Observability AI Assistant Team:AI Infra Platform AppEx AI Infrastructure Team t// v9.1.0 v8.19.0 v8.18.1 v9.0.1 labels Apr 25, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/appex-ai-infra (Team:AI Infra)

@elasticmachine
Copy link
Contributor

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

@darnautov darnautov added release_note:fix backport:version Backport to applied version labels labels Apr 25, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@darnautov
Copy link
Contributor Author

@elasticmachine merge upstream

@peteharverson peteharverson requested review from jgowdyelastic and removed request for peteharverson April 29, 2025 08:13
@darnautov darnautov removed request for a team April 29, 2025 08:24
@darnautov
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@darnautov darnautov enabled auto-merge (squash) April 30, 2025 10:33
@darnautov darnautov merged commit ccf23d0 into elastic:main Apr 30, 2025
9 checks passed
@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

cc @darnautov

@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.18, 8.19, 9.0

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

@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.18
8.19
9.0

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

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 30, 2025
…on arguments (#217680) (#219726)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[O11y AI Assistant] Correct quotes in ES|QL queries for function
arguments (#217680)](#217680)

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

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

<!--BACKPORT [{"author":{"name":"Dima
Arnautov","email":"dmitrii.arnautov@elastic.co"},"sourceCommit":{"committedDate":"2025-04-30T12:39:07Z","message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Team:Obs
AI Assistant","backport:version","Team:AI
Infra","v9.1.0","v8.19.0","v8.18.1","v9.0.1"],"title":"[O11y AI
Assistant] Correct quotes in ES|QL queries for function arguments
","number":217680,"url":"https://github.com/elastic/kibana/pull/217680","mergeCommit":{"message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217680","number":217680,"mergeCommit":{"message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Dima Arnautov <dmitrii.arnautov@elastic.co>
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 2, 2025
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @darnautov

2 similar comments
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @darnautov

@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @darnautov

@darnautov darnautov deleted the ml-216445-fix-field-escaping branch May 6, 2025 12:52
kibanamachine added a commit that referenced this pull request May 6, 2025
…n arguments (#217680) (#219727)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[O11y AI Assistant] Correct quotes in ES|QL queries for function
arguments (#217680)](#217680)

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

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

<!--BACKPORT [{"author":{"name":"Dima
Arnautov","email":"dmitrii.arnautov@elastic.co"},"sourceCommit":{"committedDate":"2025-04-30T12:39:07Z","message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Team:Obs
AI Assistant","backport:version","Team:AI
Infra","v9.1.0","v8.19.0","v8.18.1","v9.0.1"],"title":"[O11y AI
Assistant] Correct quotes in ES|QL queries for function arguments
","number":217680,"url":"https://github.com/elastic/kibana/pull/217680","mergeCommit":{"message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217680","number":217680,"mergeCommit":{"message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Dima Arnautov <dmitrii.arnautov@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request May 6, 2025
…on arguments (#217680) (#219725)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[O11y AI Assistant] Correct quotes in ES|QL queries for function
arguments (#217680)](#217680)

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

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

<!--BACKPORT [{"author":{"name":"Dima
Arnautov","email":"dmitrii.arnautov@elastic.co"},"sourceCommit":{"committedDate":"2025-04-30T12:39:07Z","message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Team:Obs
AI Assistant","backport:version","Team:AI
Infra","v9.1.0","v8.19.0","v8.18.1","v9.0.1"],"title":"[O11y AI
Assistant] Correct quotes in ES|QL queries for function arguments
","number":217680,"url":"https://github.com/elastic/kibana/pull/217680","mergeCommit":{"message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217680","number":217680,"mergeCommit":{"message":"[O11y
AI Assistant] Correct quotes in ES|QL queries for function arguments
(#217680)","sha":"ccf23d065434a255a838ef2c0b746f4db356a6fa"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Dima Arnautov <dmitrii.arnautov@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 6, 2025
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
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 :ml release_note:fix Team:AI Infra Platform AppEx AI Infrastructure Team t// Team:Obs AI Assistant Observability AI Assistant v8.18.1 v8.19.0 v9.0.1 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[O11y AI Assistant] ES|QL Creation with non standard field names does not work

5 participants