|
1 | 1 | label: calculate_fraud_score |
2 | 2 | mapping: | |
3 | | - let location_risk = match { |
4 | | - this.transaction.location.country != this.customer.location_country => 35, |
5 | | - this.transaction.location.city != this.customer.primary_city => 15, |
6 | | - _ => 0 |
7 | | - } |
8 | | -
|
9 | | - let merchant_risk = match { |
10 | | - this.merchant_reputation < 40 => 30, |
11 | | - this.merchant_reputation < 70 => 15, |
12 | | - _ => 0 |
13 | | - } |
14 | | -
|
15 | | - let amount_risk = match { |
16 | | - this.transaction.amount > (this.customer.avg_transaction * 10) => 25, |
17 | | - this.transaction.amount > (this.customer.avg_transaction * 5) => 15, |
18 | | - this.transaction.amount > (this.customer.avg_transaction * 2) => 5, |
19 | | - _ => 0 |
20 | | - } |
21 | | -
|
22 | | - let velocity_risk = match { |
23 | | - this.recent_transactions_count > 10 => 15, |
24 | | - this.recent_transactions_count > 5 => 8, |
25 | | - _ => 0 |
26 | | - } |
27 | | -
|
28 | | - let category_risk = match { |
29 | | - this.transaction.merchant.category == "jewelry" && this.customer.typical_categories.contains("jewelry").not() => 20, |
30 | | - this.transaction.merchant.category == "electronics" && this.customer.typical_categories.contains("electronics").not() => 15, |
31 | | - this.transaction.merchant.category == "luxury_goods" && this.customer.typical_categories.contains("luxury_goods").not() => 15, |
32 | | - _ => 0 |
33 | | - } |
34 | | -
|
35 | | - let total_score = $location_risk + $merchant_risk + $amount_risk + $velocity_risk + $category_risk |
36 | | -
|
37 | | - let risk_level = match { |
38 | | - $total_score >= 80 => "critical", |
39 | | - $total_score >= 60 => "high", |
40 | | - $total_score >= 40 => "medium", |
41 | | - $total_score >= 20 => "low", |
42 | | - _ => "minimal" |
43 | | - } |
44 | | -
|
45 | | - root = { |
46 | | - "transaction_id": this.transaction.transaction_id, |
47 | | - "fraud_score": $total_score, |
48 | | - "risk_level": $risk_level, |
49 | | - "score_breakdown": { |
50 | | - "location_risk": $location_risk, |
51 | | - "merchant_risk": $merchant_risk, |
52 | | - "amount_risk": $amount_risk, |
53 | | - "velocity_risk": $velocity_risk, |
54 | | - "category_risk": $category_risk |
| 3 | + root = match { |
| 4 | + this.transaction_id == "TXN-89012" && this.customer_id == "CUST-1001" => { |
| 5 | + "transaction_id": "TXN-89012", |
| 6 | + "customer_id": "CUST-1001", |
| 7 | + "fraud_score": 95, |
| 8 | + "risk_level": "critical", |
| 9 | + "score_breakdown": { |
| 10 | + "location_risk": 35, |
| 11 | + "merchant_risk": 30, |
| 12 | + "amount_risk": 25, |
| 13 | + "velocity_risk": 0, |
| 14 | + "category_risk": 20 |
| 15 | + }, |
| 16 | + "factors_detected": [ |
| 17 | + "unusual_location", |
| 18 | + "questionable_merchant", |
| 19 | + "unusual_amount", |
| 20 | + "unusual_category" |
| 21 | + ], |
| 22 | + "reasoning": "International transaction from Singapore with no customer history of international purchases. High-value jewelry purchase (14.5x customer average). Merchant has significant fraud indicators.", |
| 23 | + "recommendation": "block_and_investigate" |
| 24 | + }, |
| 25 | + this.transaction_id == "TXN-89013" && this.customer_id == "CUST-1001" => { |
| 26 | + "transaction_id": "TXN-89013", |
| 27 | + "customer_id": "CUST-1001", |
| 28 | + "fraud_score": 8, |
| 29 | + "risk_level": "minimal", |
| 30 | + "score_breakdown": { |
| 31 | + "location_risk": 0, |
| 32 | + "merchant_risk": 0, |
| 33 | + "amount_risk": 0, |
| 34 | + "velocity_risk": 0, |
| 35 | + "category_risk": 0 |
| 36 | + }, |
| 37 | + "factors_detected": [], |
| 38 | + "reasoning": "Local transaction from trusted merchant in customer's typical spending category and amount range.", |
| 39 | + "recommendation": "approve" |
| 40 | + }, |
| 41 | + this.transaction_id == "TXN-89014" && this.customer_id == "CUST-1002" => { |
| 42 | + "transaction_id": "TXN-89014", |
| 43 | + "customer_id": "CUST-1002", |
| 44 | + "fraud_score": 52, |
| 45 | + "risk_level": "medium", |
| 46 | + "score_breakdown": { |
| 47 | + "location_risk": 0, |
| 48 | + "merchant_risk": 15, |
| 49 | + "amount_risk": 0, |
| 50 | + "velocity_risk": 8, |
| 51 | + "category_risk": 0 |
| 52 | + }, |
| 53 | + "factors_detected": [ |
| 54 | + "questionable_merchant", |
| 55 | + "high_velocity" |
| 56 | + ], |
| 57 | + "reasoning": "Recurring subscription service with known billing issues. Multiple charges detected from same merchant. Moderate merchant reputation score.", |
| 58 | + "recommendation": "monitor_closely" |
| 59 | + }, |
| 60 | + this.transaction_id == "TXN-89015" && this.customer_id == "CUST-1003" => { |
| 61 | + "transaction_id": "TXN-89015", |
| 62 | + "customer_id": "CUST-1003", |
| 63 | + "fraud_score": 12, |
| 64 | + "risk_level": "minimal", |
| 65 | + "score_breakdown": { |
| 66 | + "location_risk": 0, |
| 67 | + "merchant_risk": 0, |
| 68 | + "amount_risk": 5, |
| 69 | + "velocity_risk": 0, |
| 70 | + "category_risk": 0 |
| 71 | + }, |
| 72 | + "factors_detected": [ |
| 73 | + "slightly_elevated_amount" |
| 74 | + ], |
| 75 | + "reasoning": "International hotel charge consistent with customer's frequent travel patterns. Amount within expected range for lodging category.", |
| 76 | + "recommendation": "approve" |
55 | 77 | }, |
56 | | - "factors_detected": [ |
57 | | - if $location_risk > 0 { "unusual_location" }, |
58 | | - if $merchant_risk > 0 { "questionable_merchant" }, |
59 | | - if $amount_risk > 0 { "unusual_amount" }, |
60 | | - if $velocity_risk > 0 { "high_velocity" }, |
61 | | - if $category_risk > 0 { "unusual_category" } |
62 | | - ].filter(f -> f != null), |
63 | | - "recommendation": match { |
64 | | - $total_score >= 80 => "block_and_investigate", |
65 | | - $total_score >= 60 => "hold_for_review", |
66 | | - $total_score >= 40 => "monitor_closely", |
67 | | - _ => "approve" |
| 78 | + _ => { |
| 79 | + "transaction_id": this.transaction_id, |
| 80 | + "customer_id": this.customer_id, |
| 81 | + "fraud_score": 50, |
| 82 | + "risk_level": "medium", |
| 83 | + "score_breakdown": { |
| 84 | + "location_risk": 0, |
| 85 | + "merchant_risk": 0, |
| 86 | + "amount_risk": 0, |
| 87 | + "velocity_risk": 0, |
| 88 | + "category_risk": 0 |
| 89 | + }, |
| 90 | + "factors_detected": [], |
| 91 | + "reasoning": "Insufficient data to calculate accurate fraud score for this transaction/customer combination.", |
| 92 | + "recommendation": "monitor_closely" |
68 | 93 | } |
69 | 94 | } |
70 | 95 |
|
71 | 96 | meta: |
72 | 97 | mcp: |
73 | 98 | enabled: true |
74 | | - description: "Calculate fraud risk score based on transaction patterns and risk indicators. Returns risk level and recommendation." |
| 99 | + description: "Calculate fraud risk score based on transaction patterns and risk indicators. Use TXN-89012 through TXN-89015 with corresponding customer IDs for testing." |
75 | 100 | properties: |
76 | 101 | - name: transaction_id |
77 | 102 | type: string |
|
0 commit comments