Detect Anomalies In A Time Series
Flags statistical outliers in a metric over time using rolling baselines and explains likely causes.
Prompt
ROLE: You are a monitoring analyst building anomaly detection on a business metric. CONTEXT: Detect anomalies in [METRIC] over [GRAIN] from [SOURCE_TABLE] (schema [SCHEMA]). Expected seasonality: [SEASONALITY] (e.g., weekly, daily). Engine: [DATABASE_ENGINE]. Acceptable false-positive tolerance: [TOLERANCE]. TASK: 1. Choose a baseline method appropriate to the seasonality: rolling mean +/- k*stdev, week-over-week same-day comparison, or median absolute deviation (robust to outliers). Justify the choice. 2. Write SQL using window functions to compute the baseline, the deviation, and a z-score or percentage delta per period. 3. Flag periods exceeding the threshold and label them high/low. 4. Reduce noise: require [N] consecutive breaches or an absolute-magnitude floor to avoid alerting on tiny absolute moves. 5. For any flagged point, list the next diagnostic queries to run. OUTPUT FORMAT: Method choice & rationale -> Detection ```sql``` -> Noise-reduction rules -> Follow-up diagnostics -> Limitations. CONSTRAINTS: Account for seasonality so weekends/holidays do not trigger false alarms. Use a robust statistic if outliers are heavy-tailed. Exclude the current period if it is incomplete. Make k and the window size parameters.
How to use this prompt
- 1
Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.
- 2
Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.
- 3
Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.
Techniques in this prompt
Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.
Learn this techniqueAsks the model to reason step by step before answering — ideal for multi-step, logical, or analytical tasks.
Learn this techniquePins the response to a defined structure so it drops straight into your workflow.
Learn this techniqueRecommended models
Build on this prompt
Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.
More in Data Analysis & SQL
Translate Business Questions Into SQL
Turns a plain-English stakeholder question into a correct, well-commented SQL query against a known schema.
Optimize A Slow SQL Query
Diagnoses why a query is slow and rewrites it with targeted, explained optimizations and an index plan.
Debug A SQL Query That Returns Wrong Results
Systematically finds the logic error producing incorrect numbers and delivers a corrected, verified query.
Explain An Unfamiliar SQL Query In Plain English
Reverse-engineers a complex inherited query into a clear narrative, business meaning, and risk list.