Implement payment method analysis and fraud detection with anomaly pattern recognition
harbor run -t snowflake-labs/dbt-payment-fraud-analysisharbor download snowflake-labs/dbt-payment-fraud-analysisThe Risk Management team is building a fraud prevention dashboard. "We have fraud scores per order, but I need to connect them to payment patterns. Flag any payment that looks suspicious - high amounts, high fraud scores, failed transactions, or customers with unusually high payment velocity."
Create a dbt project at /app/dbt_project with fraud analysis models in schema fraud_analytics.
/app/dbt_project/models//app/dbt_project/models/This task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Reference dbt projects exist at /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ for inspection only. Write your dbt project at /app/dbt_project — outputs in the reference directories are not graded.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
You must configure dbt to connect to the database:
profiles.yml in the dbt project directory with profile name dbt_projectDBT_PROFILES_DIR environment variable to the directory containing profiles.ymlConfigure with type: duckdb and the database path from $DUCKDB_PATH.
Configure with type: snowflake using password authentication:
ORDERS.ORDER_PAYMENTS, ORDERS.ORDERS, and ORDERS.ORDER_FRAUD_SCORESpayment_method_summary: payment_method, total_transactions, total_amount, avg_transaction_amount, success_count (CAPTURED/COMPLETED), failed_count, pending_count, failure_rate (0.0-1.0)
customer_payment_velocity: customer_id, total_payments, total_amount, distinct_payment_methods, first_payment_date, last_payment_date, days_active (min 1), payments_per_day, amount_per_day, max_single_payment, is_high_velocity
Important calculation notes for customer_payment_velocity:
PROCESSED_AT as the payment date for all date-based calculations. Do NOT use created_at or coalesce(processed_at, created_at).days_active as GREATEST(DATEDIFF('day', MIN(processed_at), MAX(processed_at)), 1) — do NOT add 1 to the DATEDIFF result. The GREATEST ensures a minimum value of 1 for customers with only one payment.fraud_risk_summary: risk_level, order_count, total_payment_amount, avg_fraud_score, failed_payment_count, pct_of_total_orders
payment_anomalies (at least 1 flag): payment_id, order_id, customer_id, payment_method, amount, processed_at, fraud_score, risk_level, anomaly_flags (comma-separated), anomaly_count