Skip to content
mentoor

Topic 4 of 5 · 4 min read

Recording which prompt and model served each request

Goal: Use logs to find which prompt and model version produced a reported answer and reproduce it.

Stamp every request with the prompt version, the exact model snapshot and the parameters, so any answer can be tied to a version and replayed. Without the stamp, "the bot said something wrong yesterday" cannot be investigated.

Check yourself · 1 of 3

A user reports a wrong answer from yesterday. Which logged field best lets you identify the exact prompt behind it?

Choose one answer

Why it matters

You will change prompts and models many times. A user report arrives with a time and a conversation id. If the log says only "model: assistant", you cannot tell which prompt wrote the answer, whether it was in a rollout group or whether the model changed under an alias. With the stamp, you search one id and see the full recipe.

What to record

On the trace (or log line) for each model call:

  • Prompt name and version: support-reply, version 4, or the git commit.
  • Model as requested and model as returned. The API response usually names the model that actually served the call. Record both; they differ when you use an alias.
  • Parameters: temperature, max tokens, stop sequences, tool list version, output schema version.
  • Rollout arm: control or candidate, and the experiment id.
  • Request id and trace id, plus the provider's response id.
  • Inputs needed to replay: the rendered messages or a reference to them, kept under your retention and privacy rules. Redact personal data you do not need.

OpenTelemetry's generative AI conventions define standard attribute names for model, request parameters and response id, so use those names rather than inventing your own, and add your prompt version as a custom attribute.

How to reproduce an answer

  1. Find the trace by conversation id or time.
  2. Read the stamp: prompt v4, model snapshot, temperature 0.2.
  3. Load that exact prompt version and render it with the stored inputs.
  4. Call the same snapshot with the same parameters. Remember that sampling is random unless the provider offers a seed, so you may get a different wording. A reproduction means the same recipe, and often the same kind of failure, not necessarily identical text.

Before and after

{ "msg": "llm call ok", "latency_ms": 2140 }
{ "msg": "llm call ok", "latency_ms": 2140, "prompt": "support-reply", "prompt_version": 4,
  "model_requested": "claude-sonnet-4-5", "model_served": "claude-sonnet-4-5-20250929",
  "temperature": 0.2, "arm": "candidate", "trace_id": "9f3c1a", "response_id": "msg_01XyZ" }

What goes wrong

  • Only the alias is logged. The snapshot behind it changed and you cannot tell.
  • The version is set at deploy time, not per call. During a gradual rollout every line shows the same version.
  • Raw user text is logged with no redaction or retention limit, which creates a privacy problem.

Examples

Finding the version behind a complaint

{"ts":"2026-11-30T14:02:11Z","conv":"c_8841","prompt":"refund-policy","prompt_version":7,
 "model_requested":"gpt-5","model_served":"gpt-5-2025-08-07","temperature":0.7,"arm":"candidate"}

The complaint names conversation c_8841. The log shows version 7 on the candidate arm with temperature 0.7. The investigator loads refund-policy v7 and reruns the input at the same settings.

Alias hides a change

The log says model: claude-sonnet-4-5 for six months. Quality shifts in March. Because only the alias was logged, nobody can say whether a new snapshot started serving. Logging the served model from each response would have shown the date it changed.

Key points

  • Put prompt name, prompt version, model snapshot and parameters on every trace or log line for a model call.
  • Record both the requested model name and the model the response says served it.
  • Stamp the rollout arm per call, so you can compare control and candidate in logs.
  • Use standard attribute names such as OpenTelemetry's generative AI conventions where they exist.
  • Reproducing an answer means loading the same version and parameters, and sampling may still change the wording.

Common mistakes

  • Logging the model alias but not the snapshot the response reports.
  • Taking the version from the deploy config instead of from the call that actually ran.
  • Omitting the rollout arm, which makes control and candidate impossible to separate in logs.
  • Storing full user inputs forever with no redaction.

Check yourself · 2 of 3

Why log the model name the response reports, not only the name you requested?

Choose one answer

Check yourself · 3 of 3

During a 25 percent rollout, every log line shows prompt_version 5, because the value is read from the deploy config. What is wrong?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic