Lesson 2 of 3 Monitoring GenAI Applications

Monitoring Token Usage, Quality and Behavioral Drift

This lesson covers generative AI key performance indicators, anomaly detection and cost monitoring, which tell you whether answers are good, costs are controlled and behaviour is changing.

Learning outcomes

After completing this lesson, you will be able to:

  • Track generative AI key performance indicators.
  • Detect bursts and drift with CloudWatch anomaly detection.
  • Run scheduled benchmarks and cost anomaly detection.

GenAI key performance indicators

Token usage per model, application, feature and tenant, and tokens per request, track cost and capacity. Prompt effectiveness measures whether prompts achieve their purpose: task success rate, format validity rate, user ratings and escalations per prompt version. Hallucination rate is estimated from contextual grounding check failures, LLM-judge faithfulness scores on sampled responses and golden dataset runs. Response quality combines judge scores, user feedback and task outcomes. These are published as custom CloudWatch metrics with dimensions for model, prompt version and feature.

# Embedded metric format: one log line becomes metrics without a PutMetricData call
print(json.dumps({
  "_aws": {"Timestamp": int(time.time() * 1000), "CloudWatchMetrics": [{
      "Namespace": "Assistant/GenAI", "Dimensions": [["Feature", "PromptVersion"]],
      "Metrics": [{"Name": "FaithfulnessScore"}, {"Name": "FormatValid"}, {"Name": "OutputTokens"}]}]},
  "Feature": "claims-qa", "PromptVersion": "7",
  "FaithfulnessScore": 0.91, "FormatValid": 1, "OutputTokens": 212
}))
Sort into groups

Which KPI family?

Exam skills 4.3.2

Decide which GenAI key performance indicator each measurement belongs to.

Log in to try this activity Interactive activities are free with an account.

Anomaly detection for bursts and drift

CloudWatch anomaly detection learns the normal pattern of a metric, including daily and weekly seasonality, and alarms when values leave the expected band. It suits token burst patterns (a sudden spike in tokens from one tenant, possibly misuse or a runaway agent) and metrics whose normal level changes over the day. Response drift is detected by tracking distributions of response length, refusal rate, sentiment, language and judge scores over time, and by comparing embeddings of current responses to a golden set with those from a reference period; a drop in similarity or quality after a model or prompt update triggers investigation.

Scenario questions

Detecting the unusual

Exam skills 4.3.2

Choose the monitoring approach for each pattern.

Log in to try this activity Interactive activities are free with an account.

Benchmarks and cost anomaly detection

Performance benchmarks run on a schedule, for example a nightly golden dataset run with latency measurements, to detect regressions from provider-side model updates or configuration drift. AWS Cost Anomaly Detection uses machine learning on cost and usage data to alert on unusual spend by service, account or cost allocation tag, catching cost problems that token metrics might not attribute to a cause. AWS Cost Explorer analyses spend trends, including by tagged application inference profile. The following table summarises GenAI monitoring signals.

SignalSourceDetects
Tokens per tenant or featureToken metrics; custom metricsCost growth; misuse; runaway agents
Format validity and task successApplication validation metricsPrompt effectiveness problems
Grounding failures and faithfulnessGuardrail metrics; judge scoresHallucination rate
Response length, refusal rate, similarity to baselineCustom metricsResponse drift
Nightly golden-set scores and latencyScheduled benchmarkRegressions
Spend by service or tagCost Anomaly Detection; Cost ExplorerUnexpected cost

The following diagram contrasts flat operational metrics with a falling quality benchmark for an assistant whose answers became vaguer.

A quality decline that operational metrics missed. Latency and errors stayed flat for two weeks while answers became vaguer. A nightly golden dataset benchmark with LLM-judge scores, and custom metrics for faithfulness and response length, show the decline, and anomaly detection alarms on them catch the next one early.
The curves are illustrative.
Worked example

Silent quality decline

Users report that an assistant's answers have become vaguer over two weeks. Latency and error metrics are normal.

Operational metrics cannot detect this. A nightly golden dataset benchmark with LLM-judge scores, plus custom metrics for faithfulness on sampled traffic and response length, would have shown the decline; anomaly detection alarms on these metrics catch the next one early, and invocation logs show which prompt version or model was involved.

Check yourself

Which alarm type catches unusual token bursts on a seasonal metric?

Show answer

A CloudWatch anomaly detection alarm.

Exam Tips

Remember for the exam

  • Monitor tokens, prompt effectiveness, hallucination rate and quality as custom metrics.
  • Anomaly detection alarms catch token bursts and seasonal metrics.
  • Detect drift with output statistics and golden-set comparisons.
  • Unexpected spend: Cost Anomaly Detection.