All posts

"Observability for AI systems: what to log so failures are debuggable"

When a normal service fails you get a stack trace. When an AI system fails there is often no error at all, just a wrong answer, discovered days later. Here is what to log, trace and alert on so that failure is diagnosable rather than a mystery.

AI engineering5 min read20 July 2026by Ahmed
"Observability for AI systems: what to log so failures are debuggable"

When a conventional service fails, you get a stack trace. Something threw, a log line points at the file and the line, and an engineer can start work within minutes. When an AI system fails, there is often no error at all. The model returned a response, the HTTP status was 200, every box on the dashboard stayed green, and the answer was wrong. You find out three days later when a customer complains or a number does not reconcile, and by then the context that produced the failure is gone.

That is the core difficulty: the failure mode of an LLM system is semantic, not mechanical. Retries, health checks and error-rate alerts, the whole apparatus built for conventional services, will sit there reporting that everything is fine while the system quietly produces confident nonsense. Observability for AI systems cannot be bolted on after the first incident. It has to be designed in, and it has to answer a different question: not "did the call succeed?" but "what exactly did the model see, and what exactly did it decide?"

The first rule is blunt: capture the full prompt and the full response for every model call. Not a summary, not the template, the rendered prompt as it went over the wire, with the retrieved documents, the system message and the examples included. Prompts are assembled dynamically from enough moving parts that reconstructing one after the fact is guesswork; when I mentor developers shipping their first LLM feature, "show me exactly what the model saw" is the first question I teach them to ask. This does mean taking retention and personal data seriously from day one: decide how long traces live, encrypt them at rest, and redact or tokenise personal data before it reaches the log store. Those are solvable problems. An undebuggable production system is not.

"Observability for AI systems: what to log so failures are debuggable"

I learned this the ordinary way. An LLM automation I run that processes incoming documents produced an output that was wrong but entirely confident, correct format, plausible values, every validation check green. The only reason it was diagnosable at all was that the full prompt sat in the trace. The input document contained an ambiguity nobody had anticipated: two fields that are normally distinct happened to carry the same label, and the model picked the wrong one, quite reasonably. Without the recorded prompt I would have been staring at a bad output with no way to tell whether the model, the retrieval or the document itself was at fault.

Second, log the decision context, not just the text. Which tools did the model choose to call, and with what arguments? What confidence did it report, per field, if you are extracting structured data? Which validation checks passed and which failed? In my own extraction work every field carries a confidence score and a validation verdict, and low-confidence fields route to a human review queue instead of flowing silently downstream. When something goes wrong, that metadata tells you whether the system knew it was uncertain, which changes the fix entirely.

Third, if you run multi-step agents or chains, trace runs end to end. A bad final answer at step seven usually has its root cause at step two, and you need to replay the whole path, every intermediate prompt, tool result and decision, to find it. Langfuse is what I reach for: the core is MIT-licensed and self-hostable, and it ingests standard OpenTelemetry traces, which matters because OpenTelemetry now defines semantic conventions for generative AI, agreed attribute names for model calls, token usage and tool invocations. Those conventions are still marked experimental as of mid-2026, but the shape has settled, and instrumenting against an open standard means your traces outlive your choice of vendor. Be honest about the floor, though: a well-structured log table with a run ID, a step number and a payload column gets you surprisingly far before you need dedicated tooling.

Fourth, track token spend and latency per feature, not just per API key. A single aggregate bill tells you nothing when one feature quietly triples its context size after a prompt change. Per-feature metrics turn "the model bill doubled last month" into "the summariser is now sending entire threads instead of the last five messages", which is a fix rather than a mystery.

Finally, alert on business metrics as well as technical ones. Documents processed per hour. Review-queue depth. The percentage of outputs that pass validation first time. Model drift, a subtly degraded prompt after a provider update, a new document format from a supplier, none of these throw errors. They show up as the review queue creeping from five items to forty over a fortnight. The business metric moves first; the error rate may never move at all.

None of this is glamorous. It is schema design, retention policy and dashboard wiring, the same unfashionable discipline that makes any production system operable. But it is the difference between an AI system you can operate and one you just have to hope keeps behaving. My public repo, github.com/afareed007/docextract, shows the shape of it in working code: per-field confidence, validation gates, optional Langfuse tracing, and an eval harness that fails CI when quality regresses.

This is exactly the work I do, designing and building AI systems that are debuggable at 3am, not just impressive in the demo. If you are running LLMs in production and dreading the first silent failure, get in touch via the contact form.

Senior engineering roles — or production AI consulting?

I'm open to senior AI and software engineering roles and to selective consulting on agents, RAG, and LLM automation in production. If this post resonates — as a hiring manager or as someone shipping similar work — get in touch.

Get in touch

© 2026 Ahmed Fareed. All rights reserved.

LOADING