Create a rule - Amazon Fraud Detector

Create a rule

A rule is a condition that tells Amazon Fraud Detector how to interpret variable values during a fraud prediction. A rule consists of one or more variables, a logic expression, and one or more outcomes. A detector must have at least one associated rule. Rules in a detector are evaluated as part of a fraud prediction.

Expressions

Each rule must contain a single expression that captures your business logic. All expressions must evaluate to a Boolean value (true or false) and be less than 4,000 characters in length. If-else type conditions are not supported. All variables used in the expression must be predefined in the evaluated event type.

To create a rule using the AWS Console, see Step 3: Add rules to a detector.

Create a rule using the AWS SDK for Python (Boto3)

The following example creates three different rules (high_fraud_risk, medium_fraud_risk, and low_fraud_risk). The example assumes you have completed the steps outlined in Build a model and created the model sample_fraud_detection_model. The example also assumes you have created the outcomes verify_customer, review, and approve (see Create an outcome for details on how to create an outcome). The expressions compare the model score output variable sample_fraud_detection_model_insightscore against various thresholds to determine the level of risk for an event.

import boto3 fraudDetector = boto3.client('frauddetector') fraudDetector.create_rule( ruleId = 'high_fraud_risk', detectorId = 'sample_detector', expression = '$sample_fraud_detection_model_insightscore > 900', language = 'DETECTORPL', outcomes = ['verify_customer'] ) fraudDetector.create_rule( ruleId = 'medium_fraud_risk', detectorId = 'sample_detector', expression = '$sample_fraud_detection_model_insightscore <= 900 and $sample_fraud_detection_model_insightscore > 700', language = 'DETECTORPL', outcomes = ['review'] ) fraudDetector.create_rule( ruleId = 'low_fraud_risk', detectorId = 'sample_detector', expression = '$sample_fraud_detection_model_insightscore <= 700', language = 'DETECTORPL', outcomes = ['approve'] )

After you create the rules, you can Create a detector version.

You can update a rule by calling the UpdateRuleVersion API. The following example updates the model score thresholds for the rules high_fraud_risk and medium_fraud_risk from 900 to 950.

fraudDetector.update_rule_version( rule = { 'detectorId' : 'sample_detector', 'ruleId' : 'high_fraud_risk', 'ruleVersion' : '1' }, expression = '$sample_fraud_detection_model_insightscore > 950', language = 'DETECTORPL', outcomes = ['verify_customer'] ) fraudDetector.update_rule_version( rule = { 'detectorId' : 'sample_detector', 'ruleId' : 'medium_fraud_risk', 'ruleVersion' : '1' }, expression = '$sample_fraud_detection_model_insightscore <= 950 and $sample_fraud_detection_model_insightscore > 700', language = 'DETECTORPL', outcomes = ['review'] )