By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A customer reports that Nova told them they would get a refund. You open the logs. There is a line: 200 OK, 1.2s. That is it. You cannot see the prompt, the retrieved documents, the answer, or the model version. You have an incident you cannot investigate.
Logging is not bureaucracy. For AI systems it is the difference between a five-minute fix and a two-day mystery.
| Log it | Why |
|---|---|
| request_id | Joins the answer to the customer's ticket |
| prompt_id + prompt_version | Tells you which wording produced it |
| model + model_version | Silent provider updates change behaviour |
| full prompt (system + context + user) | The single most useful artefact |
| retrieved chunk IDs and order | Distinguishes retrieval bugs from generation bugs |
| answer text | The thing under investigation |
| finish_reason, tokens, latency | Truncation, cost and speed in one line |
| judge score, if evaluated | Ties production to your offline metrics |
| Never log | Because |
|---|---|
| API keys or bearer tokens | One log aggregator leak is a full compromise |
| Full card numbers, passwords, health data | Regulated data in a log is a breach |
| Other customers' records | Cross-tenant leakage is the worst failure mode |
| Raw PII when a hash or ID would do | You probably only need the customer ID |
import json, logging, sys, uuid
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter("%(message)s"))
log = logging.getLogger("nova")
log.addHandler(handler)
log.setLevel(logging.INFO)
def log_turn(question, answer, chunks, meta, judge_score=None):
log.info(json.dumps({
"event": "ai_turn",
"request_id": meta["request_id"],
"prompt_version": meta["prompt_version"],
"model": meta["model"],
"question": question,
"answer": answer,
"chunk_ids": [c["id"] for c in chunks],
"tokens_in": meta["tokens_in"],
"tokens_out": meta["tokens_out"],
"latency_ms": meta["latency_ms"],
"finish_reason": meta["finish_reason"],
"judge_score": judge_score,
}))One JSON object per line. Every log platform can filter, group and chart this. A human-readable string cannot be aggregated, and that is exactly what you need during an incident.
Whoever reads the log is tired and does not have the context you have now. Optimise for them:
assert failed but q_014 faithfulness 0.31 below floor 0.50.Key takeaways
Log the full prompt, retrieved chunk IDs, answer, model version and finish_reason.
Structured JSON lines beat prose strings for anything you need to search or chart.
Never log secrets or regulated data — redact at the source, not downstream.
Failure messages must name the case, the expected value and the actual value.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.