Skip to content

Conversation

@klacabane
Copy link
Contributor

Summary

Add a severity_score to the queries generated by AI

@klacabane klacabane added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:streams-program Team Label for Streams program v9.3.0 Feature:SignificantEvents labels Dec 1, 2025
@klacabane klacabane marked this pull request as ready for review December 1, 2025 13:24
@klacabane klacabane requested a review from a team as a code owner December 1, 2025 13:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/streams-program-team (Team:streams-program)

### Example 1: Calling `add_queries` with a single query

`>>> ACTION: add_queries(queries=[{"title": "View all errors", "kql": "error.message:*", "category": "error"}])`
`>>> ACTION: add_queries(queries=[{"title": "View all errors", "kql": "error.message:*", "category": "error", "severity_score": 60}])`
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we go from 0.0 - 1.0 or from 0 to 100?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we discussed offline and will go with 0-100 to align with anomaly detection scoring

Copy link
Contributor

Choose a reason for hiding this comment

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

++, lets also document this somewhere in the code.

…atus --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/security/role --include-path /api/spaces --include-path /api/streams --include-path /api/fleet --include-path /api/saved_objects/_import --include-path /api/saved_objects/_export --include-path /api/maintenance_window --include-path /api/agent_builder --update
| `operational` | 30 | -10 expected lifecycle events |
| `configuration` | 25 | +10 security-related changes |

**Score ranges:** 80-100 critical, 60-79 high, 40-59 medium, 0-39 low
Copy link
Contributor

Choose a reason for hiding this comment

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

@shahzad31 If we can overload a prompt, means we can overload this scoring in case we need / want to adjust it.

QueryLink,
} from '../../../../common/assets';
import { QUERY_KQL_BODY, QUERY_FEATURE_FILTER, QUERY_FEATURE_NAME, QUERY_TITLE } from './fields';
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

@cesco-f I remember you had a PR to refactor this? Just stumbled over it as it is kind of odd to that we modify the asset client for sig events. But not urgent.

@ruflin
Copy link
Contributor

ruflin commented Dec 1, 2025

What happens to existing sig events queries that don't have the score yet? Is it just 0?

@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner December 1, 2025 14:00
@klacabane
Copy link
Contributor Author

klacabane commented Dec 1, 2025

What happens to existing sig events queries that don't have the score yet? Is it just 0?

@ruflin the score is currently optional so it won't be defined for existing queries as it sounds difficult to provide a correct backfill default, but if we want to I'd be more inclined to set something in the 50-70 range than 0

@ruflin
Copy link
Contributor

ruflin commented Dec 1, 2025

Having the score optional is great. Lets keep it that way.

@ruflin ruflin requested a review from Copilot December 1, 2025 15:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a severity_score field to AI-generated queries in the streams significant events system. The severity score is a numeric value (0-100) that indicates the criticality of events matched by each query.

Key changes:

  • Added severity_score as an optional numeric field to query schemas and storage
  • Updated AI prompt system to include severity scoring guidelines with category-based baselines
  • Modified data flow to propagate severity scores through the generation and storage pipeline

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
x-pack/platform/plugins/shared/streams/server/lib/streams/assets/fields.ts Defines new QUERY_SEVERITY_SCORE field constant
x-pack/platform/plugins/shared/streams/server/lib/streams/assets/storage_settings.ts Adds severity_score as a long type field in storage schema
x-pack/platform/plugins/shared/streams/server/lib/streams/assets/asset_client.ts Updates storage/retrieval logic to handle severity_score in query links
x-pack/platform/plugins/shared/streams/server/lib/significant_events/read_significant_events_from_alerts_indices.ts Propagates severity_score to significant events returned from alerts
x-pack/platform/plugins/shared/streams/server/lib/significant_events/generate_significant_events.ts Includes severity_score when generating event definitions
x-pack/platform/packages/shared/kbn-streams-schema/src/queries/index.ts Adds optional severity_score field to query schema and validation
x-pack/platform/packages/shared/kbn-streams-schema/src/api/significant_events/index.ts Makes severity_score required in generated event query interface
x-pack/platform/packages/shared/kbn-streams-ai/src/significant_events/system_prompt.text Documents severity scoring system with category baselines and modifiers
x-pack/platform/packages/shared/kbn-streams-ai/src/significant_events/prompt.ts Adds severity_score as required numeric field (0-100) in AI tool schema
x-pack/platform/packages/shared/kbn-streams-ai/src/significant_events/generate_significant_events.ts Includes severity_score in Query interface
oas_docs/output/kibana.yaml Updates OpenAPI spec with severity_score field
oas_docs/output/kibana.serverless.yaml Updates serverless OpenAPI spec with severity_score field
oas_docs/bundle.serverless.json Updates serverless API bundle with severity_score
oas_docs/bundle.json Updates API bundle with severity_score

filter: Condition;
type: string;
};
severity_score: number;
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The severity_score field is required in GeneratedSignificantEventQuery but optional in the schema definitions (streamQueryKqlSchema and upsertStreamQueryRequestSchema). This inconsistency could cause runtime errors when queries without severity_score are processed. Consider making this field optional here as well, or ensure it's always provided during generation.

Suggested change
severity_score: number;
severity_score?: number;

Copilot uses AI. Check for mistakes.
},
},
required: ['kql', 'title', 'category'],
required: ['kql', 'title', 'category', 'severity_score'],
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The AI prompt marks severity_score as required in the tool schema, but the data schema in kbn-streams-schema defines it as optional. This mismatch could cause issues if non-AI code paths create queries without severity scores. Align the requirement status across the codebase or add validation to handle missing values.

Suggested change
required: ['kql', 'title', 'category', 'severity_score'],
required: ['kql', 'title', 'category'],

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is on purpose. existing queries do not have a score and we chose not to backfill that value

Copy link
Contributor

@miltonhultgren miltonhultgren left a comment

Choose a reason for hiding this comment

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

LGTM, tested locally and see the API respond as expected, UI not updated yet.

Also, more insight will likely come as we start looking at the evaluations for these prompts!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/streams-schema 178 180 +2

Async chunks

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

id before after diff
streamsApp 1.0MB 1.0MB +66.0B
Unknown metric groups

API count

id before after diff
@kbn/streams-schema 178 180 +2

@klacabane klacabane merged commit 5723088 into elastic:main Dec 2, 2025
12 checks passed
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Dec 2, 2025
## Summary

Add a `severity_score` to the queries generated by AI

---------

Co-authored-by: kibanamachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:SignificantEvents release_note:skip Skip the PR/issue when compiling release notes Team:streams-program Team Label for Streams program v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants