from logs-aws_bedrock.invocation-*
// Filter for policy-blocked requests
| where gen_ai.policy.action == "BLOCKED"
// count number of policy matches per request (multi-valued)
| eval Esql.ml_policy_violations_mv_count = mv_count(gen_ai.policy.name)
// Filter for requests with more than one policy match
| where Esql.ml_policy_violations_mv_count > 1
// keep relevant fields
| keep
gen_ai.policy.action,
Esql.ml_policy_violations_mv_count,
user.id,
gen_ai.request.model.id,
cloud.account.id
// Aggregate requests with multiple violations
| stats
Esql.ml_policy_violations_total_unique_requests_count = count(*)
by
Esql.ml_policy_violations_mv_count,
user.id,
gen_ai.request.model.id,
cloud.account.id
// sort by number of unique requests
| sort Esql.ml_policy_violations_total_unique_requests_count desc
Install detection rules in Elastic Security
Detect AWS Bedrock Guardrails Detected Multiple Policy Violations Within a Single Blocked Request in the Elastic Security detection engine by installing this rule into your Elastic Stack.
To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(opens in a new tab or window).