I'm Gopi Gugan, a software engineer building AI features with FastAPI, Postgres/pgvector, and React/TypeScript. You can find more of my work at https://www.gopigugan.ca/. I recently shipped an LLM feature that worked well in testing — and then watched it quietly drift in production. Nothing crashed. The model just got a little worse, a little slower, a little more expensive, and nobody noticed for a week. That is the failure mode of LLM features: they do not fail loudly, they fade. So I built monitoring for it, and this is what I actually watch.

Latency, cost, and errors — the boring three

Before anything clever, I track the same three things I would track for any API endpoint.

  • Latency: p50 and p95 per request, split by model and by feature, so one slow prompt does not hide inside an average
  • Cost: tokens in, tokens out, and dollars per request — logged with every call, not estimated later from a bill
  • Errors: provider timeouts, rate limits, and malformed responses, counted separately so I know which one is actually hurting me

These are boring, and they catch most of the real problems. A prompt that suddenly doubles in cost usually means the input is growing — someone pasted a whole document where a paragraph used to go. A latency spike is often a model version change, not my code.

Log the prompts and the answers, not just the metrics

Metrics tell me something is wrong. Traces tell me what. I log every LLM call with the prompt, the response, the model, the token counts, and how long it took — plus a request ID that ties it back to the user action that triggered it.

  • Keep the full trace, not just the final answer — I need to see the exact prompt the model saw
  • Sample aggressively for high-volume features (I keep 10% of routine calls, 100% of failures and flagged ones), so logging never becomes the bottleneck
  • Redact secrets and personal data before the trace leaves the request — once it is in a log store, it is hard to take back
  • Store traces where I can search them, not in a file I will never open

When a user reports a bad answer, the first thing I do is pull the trace. Half the time the prompt was not what I expected — a missing instruction, a stale piece of context, a tool result that arrived empty.

Watch quality, not just uptime

An LLM can be up, fast, and cheap while giving bad answers. That is the gap normal monitoring misses. So I run a small, continuous quality check on top of production traffic.

  • Golden prompts: a fixed set of 20–30 prompts I run against production every hour, scored by simple checks (did it refuse when it should, did it cite the right source, did it follow the format)
  • User signals: thumbs-down, "try again" clicks, and follow-up corrections — cheap signals that are worth more than my own judgement
  • Drift alerts: if the pass rate on golden prompts drops for an hour, I get notified the same way I would for a 500 error

I keep the scoring simple on purpose. A hand-graded eval set run hourly beats a fancy automated judge I never look at. The point is a number that moves when the model's behaviour moves, not a perfect measurement.

A small logging wrapper, in plain Python

Here is roughly how I wrap every LLM call, so the metrics and traces come for free instead of being bolted on later:

import time import logging logger = logging.getLogger("llm") def call_llm(prompt, *, model, request_id): start = time.monotonic() try: reply = llm.chat(prompt, model=model) latency_ms = int((time.monotonic() - start) * 1000) logger.info("llm_call", extra={ "request_id": request_id, "model": model, "prompt": prompt, "response": reply.content, "tokens_in": reply.usage.input_tokens, "tokens_out": reply.usage.output_tokens, "latency_ms": latency_ms, }) return reply.content except Exception: logger.error("llm_error", extra={ "request_id": request_id, "model": model, "latency_ms": int((time.monotonic() - start) * 1000), }) raise 

The wrapper does three things: it measures, it logs the trace with the request ID, and it separates errors from slow successes. Everything downstream — dashboards, alerts, cost reports — reads from these logs. One wrapper, one source of truth.

What I would do first

If your LLM feature is already live and unmonitored, do not build a platform. Start with this:

  1. Wrap every LLM call in one function that logs the prompt, response, tokens, latency, and request ID
  2. Put latency, cost, and error rate on a dashboard you already check — next to your other endpoints, not in a separate tool
  3. Pick 20 golden prompts and run them hourly, with an alert when the pass rate drops
  4. Review a random sample of traces every week — the bad answers teach you more than the metrics

LLM features fail quietly, so monitoring them is not optional polish — it is how you find out something went wrong before your users tell you. Log the traces, watch the quality, and keep a human in the loop on the alerts.

Ship the monitoring with the feature, not after it.