What should you log for every LLM call in production, and what are the pitfalls?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Per call, the useful minimum:
- Identity & versions: request/trace ID, user/session ID (pseudonymous), prompt-template name + version, model + exact version (not an alias), sampling params (temperature, max_tokens), tool/function schemas offered.
- Content: the full rendered prompt (system + messages) and completion - or redacted/pointer forms where policy requires. Also intermediate artifacts: retrieved chunks with IDs and scores, tool calls with arguments and results.
- Performance & cost: input/output token counts, time-to-first-token, total latency, retries, cache hits, computed cost.
- Outcome signals: finish reason (stop, length, tool_use, content_filter), guardrail check results, downstream feedback (thumbs, regeneration, escalation) joined by trace ID.
Full worked answer
Per call, the useful minimum:
- Identity & versions: request/trace ID, user/session ID (pseudonymous), prompt-template name + version, model + exact version (not an alias), sampling params (temperature, max_tokens), tool/function schemas offered.
- Content: the full rendered prompt (system + messages) and completion - or redacted/pointer forms where policy requires. Also intermediate artifacts: retrieved chunks with IDs and scores, tool calls with arguments and results.
- Performance & cost: input/output token counts, time-to-first-token, total latency, retries, cache hits, computed cost.
- Outcome signals: finish reason (stop, length, tool_use, content_filter), guardrail check results, downstream feedback (thumbs, regeneration, escalation) joined by trace ID.
Structure it as a trace: a tree of spans, one per model call / retrieval / tool execution, so a multi-step agent request reads as a single navigable object. OpenTelemetry's GenAI semantic conventions standardise attribute names (gen_ai.request.model, gen_ai.usage.input_tokens, ...) so you're not locked to one observability vendor.
Pitfalls, in order of severity:
- PII. Prompts and completions are user data - often the most sensitive text your company stores. You need a retention policy, redaction or tokenization of identifiers at ingestion, access controls (support engineers ≠ everyone), and the ability to honour deletion requests. "Log everything forever in plaintext" is a GDPR/compliance incident on a timer.
- Logging the alias, not the version.
model: gpt-latest-style logging makes provider-side upgrades invisible; you can't explain why quality shifted on a Tuesday. - Missing the join keys. If feedback events can't be joined back to the exact trace (prompt version, retrieved chunks), your error-analysis loop is dead.
- Volume/cost: full prompt logging at scale is expensive - sample intelligently (keep 100% of errors and negative feedback, sample successes).
What a good answer covers
- Identity & versions: request/trace ID, user/session ID (pseudonymous), prompt-template name + version,…
- Content: the full rendered prompt (system + messages) and completion - or redacted/pointer forms where…
- Performance & cost: input/output token counts, time-to-first-token, total latency, retries, cache hits,…
- Outcome signals: finish reason (stop, length, tool_use, content_filter), guardrail check results,…
- Structure it as a trace: a tree of spans, one per model call / retrieval / tool execution, so a…
Key terms: Identity & versions · Content · Performance & cost · Outcome signals · trace · PII · Missing the join keys · Volume/cost
In the glossary: Temperature · Tool call · Observability
Interviewer follow-ups to expect
How would you implement "delete this user's data" when their text appears inside other logged prompts?
What would you log differently for a voice agent?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep