Data Analysis & SQL5.0 · 0 ratings

Detect Anomalies In A Time Series

Flags statistical outliers in a metric over time using rolling baselines and explains likely causes.

Role-BasedChain-of-ThoughtStructured-Output

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. 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. 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. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique
Chain-of-Thought

Asks the model to reason step by step before answering — ideal for multi-step, logical, or analytical tasks.

Learn this technique
Structured Output

Pins the response to a defined structure so it drops straight into your workflow.

Learn this technique

Recommended models

claudegpt-4ogemini

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