Lesson 28 of 30
A normal API log tells you a request happened and what it returned — an AI call needs more than that, because the same input can legitimately produce a different output next time.
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
A user reports that an AI tutor feature gave them a confusing, wrong explanation yesterday. Why is a generic API log ("chat request, 200 OK, 1.2s") not enough to debug this?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
The generic observability principle — logging discrete events, monitoring aggregate metrics, being able to answer a new question about system behavior after the fact without shipping a new debug build — applies to AI features too, but a normal API log doesn't capture what actually matters for an LLM call. Four things are specifically worth tracing:
The reason this matters specifically for AI calls, more than for a typical deterministic API: LLM output is non-deterministic. The same prompt sent twice can produce two different responses. That means "it happens sometimes" is not debuggable on its own — you need the actual historical prompt and the actual historical response for the specific bad output someone reported, not just a general sense that the feature is occasionally wrong. Without that concrete record, there's nothing to diagnose against.
const start = performance.now();
const result = await handleChat(messages, deps);
const totalMs = performance.now() - start;
logger.info("ai_chat_call", {
userId: user.id,
provider: result.provider, // which provider actually served this
model: result.model,
promptTokens: result.usage.promptTokens,
completionTokens: result.usage.completionTokens,
timeToFirstTokenMs: result.timing.ttft,
totalMs,
// the actual prompt/response pair — this is the part a generic API log skips
prompt: messages,
response: result.text,
});
If a user later reports "the tutor gave me a wrong explanation," a generic log ("chat request, 200 OK, 1.2s") gives you nothing to work with. This log gives you the exact prompt that produced that exact response — which is the only way to actually investigate a single bad output from a system that won't necessarily reproduce it if you just ask the same question again yourself.
lib/ai/chat/handler.ts), not knowing which provider actually served a given request makes a quality regression impossible to localize."A user says your AI feature gave a bad answer — how do you debug it?" is a real question, and the honest answer requires having actually logged the specific prompt/response pair, token usage, and latency breakdown ahead of time — not "we'd look into it," which isn't possible without that historical record already existing.