DEV Community

Nimish Rangani
Nimish Rangani

Posted on

How I Built a Compliance Detection Engine for TikTok Shop Affiliate Scripts

TikTok Shop's violation system is brutal for affiliates. Say the wrong phrase in a video script — "guaranteed results," "clinically proven," "cures" — and you rack up violation points without warning. Enough points and your account gets restricted. Enough restrictions and you're banned.

The problem: creators don't know which phrases are risky until after the video is already posted and flagged.

I built BanProof AI to catch violations before recording. Here's how the detection engine actually works.

The Core Problem: Policy Is Not a Simple Blocklist
My first instinct was a keyword blocklist. Ban "guaranteed," ban "cure," ban "FDA approved." Done.

That fails immediately for two reasons:

  1. Context matters. "This product guarantees fast shipping" is fine. "This product guarantees you'll lose 20 pounds" is a violation. Same word, completely different risk.

  2. Platforms update policies constantly. TikTok Shop, Amazon Associates, and the FTC all publish policy documents that evolve. A static list goes stale within weeks.

So instead of a blocklist, I built a three-layer approach:

Layer 1: Category-Based Violation Detection
I mapped out the violation categories that TikTok Shop, Amazon Associates, and the FTC actually penalize:

Absolute health claims — "cures," "eliminates," "guaranteed to treat"
Income/result guarantees — "guaranteed results," "make $X in Y days"
False certifications — "FDA approved," "clinically proven" (when not substantiated)
Competitor disparagement — explicit negative comparisons
Missing FTC disclosures — affiliate links without "ad," "#sponsored," or "I earn a commission"
Prohibited product claims — category-specific rules (supplements, skincare, etc.)
Each category has:

A set of pattern signals (not just keywords — phrase structures)
A severity level (warning / elevated / high)
A safe rewrite template
The detection layer doesn't just flag a word — it flags a violation category with an explanation.

Layer 2: Semantic Pattern Matching with Claude
Pure regex misses paraphrases. "This serum will completely fix your acne" doesn't contain "cure" or "guarantee" — but it's an absolute health claim.

I pass the script through Claude (via the Anthropic API) with a structured prompt that asks it to:

Identify phrases that match any violation category
Explain which specific policy it violates (TikTok Shop content policy, Amazon Operating Agreement, or FTC guidelines)
Rate the overall risk level
Generate a safe rewrite that keeps the original intent
The prompt is engineered around the actual policy documents — not general "is this risky?" vibes. I feed it the specific clauses from each platform's content policy that relate to the script's product category.

This means the output isn't generic AI safety warnings. It's specific: "This phrase violates TikTok Shop Content Policy §4.2 on absolute claims. Safe rewrite: 'many users love how this performs.'"

Layer 3: The MCP Server
The third layer is where it gets interesting for developers.

I wanted creators using Claude, ChatGPT, or Cursor to be able to run compliance checks without leaving their editor. So I built a live MCP (Model Context Protocol) server.

The MCP endpoint lives at https://banproof.io/mcp and exposes one tool: audit_script.

Input:

{
"script": "This serum will completely cure your acne in 3 days — guaranteed results or your money back."
}
Output:

{
"risk_level": "high",
"violations": [
{
"phrase": "completely cure your acne in 3 days",
"category": "absolute_health_claim",
"policy": "TikTok Shop Content Policy §4.2",
"safe_rewrite": "support clearer-looking skin over time"
},
{
"phrase": "guaranteed results or your money back",
"category": "result_guarantee",
"policy": "FTC Guidelines §255.1",
"safe_rewrite": "so many creators love how it performs"
}
]
}
Auth is OAuth 2.0 via Supabase — users sign in with their BanProof account and the MCP client handles token exchange. The endpoint is RFC 9728 compliant (OAuth Protected Resource Metadata).

Any MCP-compatible client — Claude Desktop, Claude Code, Cursor, or a custom agent — can connect and run audit_script natively.

What I Got Wrong Early
Mistake 1: Treating all violations equally. A missing FTC disclosure is serious but fixable with a one-line addition. A false medical claim is a fundamentally different problem. I now weight violations differently and surface the highest-severity issue first.

Mistake 2: Rewrites that changed the meaning too aggressively. Early versions would rewrite "lose 20 pounds in 30 days" as "support your wellness journey." Technically compliant, completely useless as marketing copy. The prompt now explicitly instructs the model to preserve the hook, the CTA, and the product benefit — just remove the violating mechanism.

Mistake 3: Not separating platform policies. TikTok Shop and Amazon Associates have different rules. A phrase that's fine for Amazon might violate TikTok Shop policy. I now run detection against each platform's policy set separately and merge the results, deduplicating overlapping violations.

The Stack
Frontend + auth: React + Supabase (hosted on Lovable)
Compliance engine: Anthropic Claude via API, prompted with platform-specific policy context
MCP server: Custom Node.js implementation, Streamable HTTP transport
Database: Supabase Postgres (audit history, usage tracking)
Infrastructure: Vercel (frontend), VPS for MCP
Open Questions
I'm still working through a few things:

Policy drift detection — TikTok Shop updates its policy without announcing changes. I'm building a weekly diff job that compares the published policy document against the previous version and flags new violation categories for review.

Category-specific context — A supplement script needs different violation detection than a tech gadget script. I'm adding product category as an input so the prompt loads the relevant policy clauses.

Confidence scoring — Claude's violation detection isn't always certain. I want to surface a confidence score so users know when a flag is definitive vs. borderline.

If you're building compliance tooling, content moderation, or anything that needs to reason about policy documents — the pattern of (category taxonomy) + (semantic LLM detection) + (policy-grounded rewrites) works well and is worth stealing.

BanProof AI is live with a free tier (3 audits/month, no credit card). The MCP server is at https://banproof.io/mcp if you want to connect it to your AI client.

Happy to answer questions about the MCP auth implementation or the prompt engineering in the comments.

Top comments (0)