What should you log and trace in an LLM application?
42 views
61 of 83
1
The problem
Question presented to candidate:
"You are about to launch a support chatbot with retrieval and a couple of tools. A week after launch a customer complains that the bot told them something wrong. What would you need to have logged to explain exactly what happened โ and what should you deliberately not log?"
What a strong answer should cover:
A per-request record that makes any answer reproducible: trace ID, feature, prompt name, version and hash, requested and served model, parameters, retrieved document IDs with scores, every tool call with arguments, status and latency, token usage including cached tokens, cost, time to first token and total latency, finish reason, guardrail results, errors, and the (redacted) input and output
Why LLM apps need more than classic request logs: failures are silent (a wrong answer is a 200 OK), so the content and the context that produced it are the debugging evidence
Aggregated metrics with low-cardinality labels (feature, prompt version, model): p95 latency, error and truncation rates, cache hit rate, cost per feature, refusal and guardrail rates
Privacy by design: redact or tokenise PII before the record is written, hash user IDs with a keyed hash, limit retention and access, and keep raw content out of metrics
Feedback joined by trace ID, so a thumbs-down becomes an eval candidate with the exact version and context attached
Code / implementation expected: Optional โ a log record schema or a small function that builds one with redaction and cost.
observability
tracing
logging
llmops
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Engineers building their first production LLM feature who need to decide what goes into logs, metrics and traces; also interview candidates who will be asked "how would you debug a bad answer?".
Difficulty: Medium
Verified with: Node 22.22.0 and Python 3.12.3 (the log-record builder below, identical output in both). Prices in the example are made-up round numbers, not any provider's price list.
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the words an interviewer expects. All program output shown was produced by actually running the example; the Verified section quotes it in full.
1. Why This Even Matters โ A Story First
A plane's flight recorder does not record "the flight went fine" or "the flight went badly". It records altitude, speed, every control input and
The solution is hidden so you can try first
16 min read ยท 11 sections
4
Read the code
Structured LLM log record: redaction, cost from usage, roll-ups and feedback join