Order Anomaly Detection
order_anomaliesIdentify fraud and revenue spikes by detecting statistical anomalies in recent orders, including high-value, velocity spikes, unusual quantities, off-hours, and new-customer high-value orders.
Instructions
Statistical anomaly detection on recent orders. Flags high-value orders (>3σ from mean), velocity spikes (customer ordering unusually fast), unusual quantities, off-hours purchases (2am-5am), and new-customer high-value orders. Returns an array of anomalies with order_id, anomaly_type, severity (low/medium/high), reason, and recommended_action. Useful for fraud detection and revenue spike investigation.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| store_id | Yes | UUID of a connected store (returned by store_connect with action="connect" or visible in store_connect with action="list" / the store_overview resource) |
Implementation Reference
- src/models/store.ts:165-183 (schema)Zod schemas and TypeScript types for AnomalyType (five anomaly categories) and AnomalyResult (order_id, anomaly_types, risk_score, risk_level, flags, recommended_action).
// ── Anomaly Detection ───────────────────────────────────────────── export const AnomalyTypeSchema = z.enum([ 'high_value', 'velocity_spike', 'unusual_quantity', 'off_hours', 'new_customer_high_value', ]); export type AnomalyType = z.infer<typeof AnomalyTypeSchema>; export const AnomalyResultSchema = z.object({ order_id: z.string(), order_number: z.string(), anomaly_types: z.array(AnomalyTypeSchema), risk_score: z.number().min(0).max(100), risk_level: z.enum(['low', 'medium', 'high', 'critical']), total: z.number(), customer_email: z.string().nullable(), flags: z.array(z.string()), recommended_action: z.string(), }); export type AnomalyResult = z.infer<typeof AnomalyResultSchema>;