Models

What Is Anomaly Detection?

The practice of identifying data points, events, or behaviors that deviate from a learned or expected baseline distribution.

What Is Anomaly Detection?

Anomaly detection is the discipline of identifying data points, events, or behaviors that diverge from a baseline distribution. In AI reliability, it is a model and observability practice for finding unusual prompts, responses, traces, tool calls, costs, or evaluator scores before they become incidents. Classical methods include z-score thresholds, isolation forests, one-class SVMs, and autoencoder reconstruction error; LLM systems also use embedding-distance scoring and prompt-injection detectors. FutureAGI treats anomaly detection as a per-trace signal with an anomaly score, threshold, and triage route.

Why anomaly detection matters in production LLM and agent systems

LLM and agent stacks generate enormous volumes of traces with long-tailed behaviors. Most are normal; a few are quietly catastrophic. A user prompt that is 50x longer than typical may be a benign edge case or an indirect prompt-injection attempt. A trajectory that ends with a tool call to a sensitive API may be a feature or an exploit. A response that scores 0.3 on Groundedness when the cohort baseline is 0.85 may be a one-off model hiccup or the leading edge of a regression. Aggregate dashboards average these out; anomaly detection surfaces them.

The pain is felt across roles. An ML engineer sees a daily eval score stable but cannot explain a customer complaint — the offending trace was an outlier the dashboard never highlighted. A SecOps lead chases a single jailbreak in a billion calls; only an anomaly detector with high recall can keep that needle visible. A platform engineer watches token costs creep up 8% over a week and only later discovers one tenant generating runaway-cost trajectories the gateway never flagged.

In 2026 anomaly detection becomes table stakes for every LLM observability product. The signals are richer than they were for classical ML: prompt embeddings, response embeddings, tool-call patterns, latency distributions, eval-score distributions. The opportunity is to detect not just “this is unusual” but “this is the kind of unusual that historically mapped to a specific failure mode” — and route it appropriately.

How FutureAGI handles anomaly detection

FutureAGI’s approach is to layer multiple anomaly signals on top of every trace and surface them through alerts, cohort dashboards, and triage queues. EmbeddingSimilarity compares incoming prompts and responses against learned cluster centroids, flagging outliers with a configurable threshold. PromptInjection and ProtectFlash detect anomalous input patterns that match known attack signatures. Dashboard-level signals — token-cost-per-trace, latency p99, eval-score percentile — fire alerts when they cross learned baselines. Dataset.add_evaluation lets engineers slice anomaly rates by cohort, channel, model, or version so a regression in one slice does not get drowned by stable global numbers.

A concrete example: a fintech support team runs a RAG-based banking assistant. They configure a baseline prompt embedding cluster from 30 days of normal traffic and use EmbeddingSimilarity to score every incoming prompt against the centroid. Prompts scoring below 0.3 are routed through Agent Command Center’s pre-guardrail chain for additional scrutiny. Unlike a single z-score threshold, this combines semantic novelty, security evaluators, and trace cost signals in the same triage path. After deploying this, they spot a coordinated probing campaign: 84 prompts in 12 minutes scored anomalously low and clustered in a region the team had never seen. PromptInjection flagged 37 of the 84 as direct injection attempts; the remaining 47 were a novel indirect-injection pattern using transliteration. The team’s response was to add the new pattern to a regression suite, retrain the embedding baseline, and tighten the threshold for that cohort. Without the anomaly detector, the campaign would have looked like normal long-tail traffic.

How to measure and detect anomalies

Anomaly detection itself is the measurement; here is how to evaluate the detectors:

  • Per-instance anomaly score distributions: track how scores trend over time; a flattening distribution means the detector is becoming desensitized.
  • EmbeddingSimilarity against cluster centroids: 0–1 score on prompt or response novelty; threshold per cohort.
  • PromptInjection and ProtectFlash: input-anomaly detectors aimed at security signals.
  • llm.token_count.prompt spikes: trace-level prompt tokens vs cohort baseline; surfaces runaway agents, abuse, and malformed context assembly.
  • Eval-score outliers: per-cohort percentile of eval scores like Groundedness or TaskCompletion; flag traces in the bottom 1%.
  • Detector precision and recall: rare-event detectors must be measured on labeled samples; otherwise you cannot tell if you are missing real anomalies or alarm-fatiguing the team.
  • Triage outcome rate: measure how often flagged traces become confirmed incidents, regression-eval additions, threshold changes, or dismissed alerts.

Minimal Python:

from fi.evals import EmbeddingSimilarity

sim = EmbeddingSimilarity()
result = sim.evaluate(
    response=incoming_prompt,
    expected_response=baseline_centroid_text,
)
if result.score < 0.3:
    # route to pre-guardrail chain
    pass

Common mistakes

  • Using a single global baseline. Cohort, channel, and customer-tier all change “normal”; thresholds must be per-cohort.
  • Treating drift and anomaly the same. Drift moves the whole distribution; anomalies are individual outliers. Both deserve separate detectors.
  • No labeled evaluation set. Without a labeled set of historical anomalies, you cannot measure detector precision and recall.
  • Letting alarm fatigue set the threshold. A detector tuned to fire 10 alerts a day will eventually tune itself to the wrong floor; calibrate against actual incidents.
  • Skipping anomaly logging in the LLM trace. Anomaly scores belong on the same span as the LLM call, not in a parallel system that forensics teams cannot find.
  • Ignoring negative examples. Keep benign oddities in the dataset so the detector learns what should not wake an on-call engineer.

Frequently Asked Questions

What is anomaly detection?

Anomaly detection identifies data points, events, or behaviors that deviate from a baseline distribution. It is per-instance (one outlier) rather than aggregate (a population shift), and it is used across security, fraud, monitoring, and ML evaluation.

How is anomaly detection different from drift monitoring?

Drift monitoring detects population-level distribution shift over time; anomaly detection flags individual outliers against a baseline. The two are complementary — a stream can have anomalies without drift, or drift without obvious per-instance anomalies.

How does FutureAGI surface anomalies in LLM systems?

FutureAGI flags anomalous traces using EmbeddingSimilarity against historical clusters, PromptInjection and ProtectFlash for input anomalies, and dashboard alerts on token-cost or latency spikes per cohort.