DEV Community

Cover image for New Account Fraud Detection: Audit Signups with Python
Yahor Papou for ShieldLabs

Posted on Fully Autonomous

New Account Fraud Detection: Audit Signups with Python

Author: Yahor Papou, CMO at ShieldLabs. Updated on October 27, 2026.

New account fraud detection can use a signup-cohort review to identify devices associated with several accounts and repeated introductory grants. It is a way to prioritize investigations, not a verdict that every shared device represents abuse. Count distinct accounts and benefits, deduplicate source events, and keep the review output separate from automated account restrictions.

This Python example uses an illustrative application CSV, not a ShieldLabs export contract. Its columns are chosen for the analysis. The code uses Python's standard CSV reader, sets for distinct counts, and timezone-aware timestamps so repeated deliveries and midnight boundaries do not silently change the result.

In 2026, we tested the accompanying Python analysis against synthetic duplicates, repeated grant IDs, missing identifiers, and timezone boundaries. The results verify the counting rules in this example. They are reproducible fixture outcomes, not a measured customer abuse rate.

New account fraud detection can use cohort analysis to prioritize review, but the export must distinguish observations from confirmed outcomes. Fake account prevention improves when reviewers can trace a candidate to its recorded benefits and resolve ordinary shared-device use. The script below supplies counts for that review, not an automatic restriction policy.

Define the cohort and the unit of review

Choose a bounded signup period, the applicable offer, and the account population before exporting data. Include records for legitimate evaluation cases as well as suspected abuse. If you export only flagged signups, the resulting dataset cannot tell you how common the pattern is across all new customers.

The input schema is deliberately small:

Column Meaning in this example
event_id Unique identifier from the application's export
created_at Event time with timezone
account_id Internal pseudonymous account reference
device_id Device linkage reference, if available
grant_id Stable benefit reference, blank if none

Use references appropriate to your access controls. Do not export raw credentials or unnecessary contact data. Keep missing device evidence visible in the source audit; grouping every blank device ID together would manufacture a large, meaningless cluster.

Count accounts and grants separately

Repeated event rows, repeated logins, and distinct customer accounts are different quantities. Deduplicate event delivery first, then count unique accounts and grant IDs per device. If one account generates twenty events, it should still count as one account. If one grant appears in multiple rows, it should count once.

import csv
from collections import defaultdict
from datetime import datetime, timezone

def review(rows):
    devices = defaultdict(lambda: {'accounts': set(), 'grants': set(), 'days': set()})
    seen = set()
    for row in rows:
        event_id = row['event_id'].strip()
        if not event_id:
            raise ValueError('Missing event_id')
        if event_id in seen:
            continue
        seen.add(event_id)
        stamp = datetime.fromisoformat(row['created_at'].replace('Z', '+00:00'))
        if stamp.utcoffset() is None:
            raise ValueError('Timestamp needs a timezone')
        device = row['device_id'].strip()
        account = row['account_id'].strip()
        if not device or not account:
            continue
        item = devices[device]
        item['accounts'].add(account)
        item['days'].add(stamp.astimezone(timezone.utc).date().isoformat())
        if row['grant_id'].strip():
            item['grants'].add(row['grant_id'].strip())
    return [dict(device_id=device, accounts=len(v['accounts']),
                 grants=len(v['grants']), active_days=len(v['days']))
            for device, v in sorted(devices.items())]

if __name__ == '__main__':
    import argparse, json
    parser = argparse.ArgumentParser()
    parser.add_argument('csv_file')
    args = parser.parse_args()
    with open(args.csv_file, newline='', encoding='utf-8') as f:
        print(json.dumps(review(csv.DictReader(f)), indent=2))

Enter fullscreen mode Exit fullscreen mode

Save the script as cohorts.py and run python3 cohorts.py signups.csv. It emits JSON sorted by device reference. The script skips rows without usable device or account references and rejects missing event IDs and timezone-free timestamps. Keep separate counts of skipped rows in a production analysis so coverage is explicit.

Python's datetime documentation explains aware and naive timestamps. Convert to a consistent timezone before grouping days; otherwise identical moments can appear in different daily cohorts depending on their source offset.

Read a small synthetic result

For a fixture where device d-alpha is associated with accounts A, B, and C and two distinct grants, the report shows three accounts and two grants. Duplicating one input event does not increase either count. That is an analysis invariant, not a measured abuse rate.

Synthetic device Distinct accounts Distinct grants Review question
d-alpha 3 2 Were both benefits eligible?
d-beta 1 1 Useful ordinary-case control
d-office 4 0 Is this legitimate shared equipment?

The fake-signup detection guide explains the wider detection funnel. This report adds a reproducible view of the relationship between registrations and benefits. It does not infer which person controls a device or why the accounts exist.

Turn the output into a review queue

Select review candidates using your product's eligibility unit and available capacity. A device with several accounts and no benefits may deserve a different priority from a device repeatedly receiving an expensive introductory allocation. Do not copy a vendor's detection threshold into this analysis and call it a universal abuse definition.

For each candidate, inspect the signup sequence, relevant offer terms, previous benefit grants, and known shared-device explanations. Record confirmed ineligible claims, allowed use, unresolved cases, and corrections separately. That gives you a labeled review set for later evaluation.

Use an ordinary-case sample too. Reviewing only the highest counts can show you interesting cases but cannot estimate the false-positive rate of a rule you have not applied to a representative population.

Add the tests that protect the conclusion

Run the script against a duplicated event, the same grant repeated in several rows, a missing device ID, and two timestamps representing the same UTC day with different offsets. Also test a timezone-free timestamp and decide whether your ingestion process should reject or explicitly repair it.

The accompanying fixture tests were run locally. They demonstrate the script's counting behavior, not fraud-detection accuracy or customer outcomes. Keep the raw export immutable and save the script version and cohort parameters with each report.

At larger volumes, move the same distinct-count semantics into your warehouse. Check how identity changes and missing collection affect coverage before comparing periods. A higher device-linked account count can come from better instrumentation as well as a change in account behavior.

Pair cohort review with ready detection

ShieldLabs multi-accounting prevention supplies direct multi-accounting detection, with related detections for account sharing, impossible travel, and account takeover. SDKs, API, and webhooks connect those results to account workflows. The cohort report complements detection by making benefit outcomes reviewable.

Start Free to evaluate enterprise-level functionality without enterprise pricing on the same ordinary and repeated-claim scenarios.

Analysis questions

Does a shared device prove multi-account abuse?

No. Shared equipment, households, and company workstations can produce legitimate account relationships. Use the device link to prioritize review, then assess ownership and benefit eligibility. Preserve an appeal path and record allowed use separately from confirmed ineligible claims before measuring the quality of a restriction rule.

Why count grant IDs instead of event rows?

Several events can describe one grant, and delivery can duplicate a row. Counting stable distinct grant IDs measures the number of recorded benefits rather than message volume. Keep that measure separate from distinct accounts, because one account can generate many events without receiving another benefit.

Can this report estimate the abuse rate?

Not by itself. It identifies relationships in the exported population. Estimating abuse requires representative coverage, a defined policy, and reviewed outcomes. Report the cohort size, missing-evidence coverage, and unresolved cases alongside confirmed findings rather than labeling every candidate as an abusive signup.

References

[1] ShieldLabs: fake signup detection
[2] ShieldLabs: multi accounting prevention
[3] docs.python.org: csv.html
[4] docs.python.org: datetime.html

Questions or corrections: contact@shieldlabs.ai.

Summarize this article with

ChatGPT · Claude · Grok · Grok on X · Perplexity · Google AI

Top comments (0)