BigQuery’s TimesFM anomaly detector needs data from before the scoring window
When an analytics agent turns “flag unusual sales this week” into SQL, filtering the input to this week can remove the history TimesFM needs for comparison.
If you ask an analytics agent to flag unusual sales this week, check where it puts the date filter. In BigQuery’s AI.DETECT_ANOMALIES, the dates you want to score and the dates the model needs to see are different things. The built-in TimesFM model forecasts from the historical portion of the input and compares the actual values in the target portion against that forecast. If a generated query filters away everything before the scoring window, a cutoff at the start of that window cannot restore the missing history. Google’s function reference spells out the split.
Put the reporting cutoff in the function, not at the start of its input
For a single input containing both periods, target_start_timestamp assigns points strictly before the cutoff to history and points at or after it to the target. Google’s worked Citi Bike example aggregates daily trips, limits the input at the end of the period of interest, and sets July 1, 2016 as the target start. The input query does not discard the dates before July. To investigate a week of daily sales, use the same shape: keep earlier daily totals in the input, end it at the reporting boundary, and use the first day of the week as the scoring cutoff. Alternatively, pass separate history and target tables or queries with matching columns. Function reference and worked example
There is also a distinction between “the last seven days” and “the last seven observations.” target_last_n_points selects observations, not calendar days. With a missing daily row, seven observations can cover more than seven calendar days. Use a timestamp cutoff when the question is about dates, and choose the appropriate reporting grain before asking the function to score the series. Function arguments
A failed series is not a clean series
Inspect ai_detect_anomalies_status before summarizing the output. The reference says the status is empty on success and notes that too little history can yield an error with NULL anomaly flags, bounds and probabilities. A dashboard or agent that counts only rows where is_anomaly is true can otherwise report zero alerts without saying that scoring failed. Keep failed evaluations separate from successfully scored points that were not flagged. This guidance applies to the TimesFM-backed AI.DETECT_ANOMALIES path, not every BigQuery anomaly function.
sources
- Google Cloud: The AI.DETECT_ANOMALIES functiondocs.cloud.google.com
- Google Cloud: Anomaly detection overviewdocs.cloud.google.com
comments · 0
- EKOS’s pending BIRD submission pairs a SQLite-tuned run with a separate hidden-test scoreDec 3, 2026
- MotherDuck rolls out DuckDB 2.0 and reports faster cold reads, not faster agent answersDec 3, 2026
- Oracle Select AI can use two definitions of the same metric. Source order won’t break the tieDec 3, 2026