Skip to main content

Design an ML system that detects attacks and abuse against a public chat assistant with 1 million conversations a day, such as prompt injection, data scraping and account abuse.

System design · Pro 2

Short answer

Start from a threat model: who attacks, how, and what each attack costs. Then: log prompts, outputs, tool calls and account signals, run fast classifiers inline for injection and policy violations, run behaviour models offline for scraping and account abuse, map risk scores to tiered actions, send cases to analysts, and retrain from red-team findings and incidents.

Deeper answer

Begin with a threat model and clarify the assets: the system prompt, user data, tools the assistant can call, and compute cost. Prompt injection and jailbreaks happen inside one message or document. Scraping, model extraction and account abuse show up as behaviour over many requests.

Signals: log each request with the prompt, retrieved content, tool calls, output, account age and device. The inline path must be fast: rules for known attack strings, then a small classifier for injection and policy violations, on input and output. The offline path builds features per account and per network, such as request rate, prompt similarity across accounts and unusual tool use, and runs anomaly detection and clustering.

Actions are tiered by confidence: rate limit, challenge, block the response, suspend the account, or send to an analyst. Analyst decisions, red-team exercises and past incidents provide labels.

Trade-offs: strict thresholds block real users, and attackers adapt quickly, so measure the false positive rate on normal traffic and recall on a fresh red-team set. Tool permissions must still hold when detection fails. At scale, new attack styles, other languages and analyst workload break first.

What a strong answer covers

Answer it out loud in the mock interview about 2.5 min

Follow-ups to expect

Common mistakes

Learn it

Machine learning for threat detection

Practice System design questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.