---
title: "Log which prompt made each answer · Agent Wranglers"
url: https://agentwranglers.se/playbook/ai-features/prompts-as-code/prompt-version-in-logs
updated: 2026-10-20
licence: "All rights reserved"
---

# Log which prompt made each answer

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Prompts as code](https://agentwranglers.se/playbook/ai-features/prompts-as-code)
- Rule: Record the prompt ID, prompt version and exact model version with every model call and every stored AI output.
- How: Have the gateway add these fields to its log line and return them with the result. Save them in the same row as any AI output you store, such as a draft reply or a summary. When a user reports a bad answer, you can then rerun the exact prompt and model. The full list of log fields is in [log every model call](https://agentwranglers.se/playbook/ai-features/logs-privacy-and-feedback/log-model-calls).
- Check: Query the stored AI outputs from the last day. Every row has a prompt ID, a prompt version and a model version, and none is empty.

Example:

```sql
SELECT count(*) FROM ai_outputs
WHERE created_at > now() - interval '1 day'
  AND (prompt_id IS NULL OR prompt_version IS NULL OR model_version IS NULL);
-- PASS when the count is 0
```

```ts
await db.aiOutputs.insert({ orderId, text: answer.text, promptId: prompt.id, promptVersion: prompt.version, modelVersion: answer.model });
```

```python
db.ai_outputs.insert(order_id=order_id, text=answer.text, prompt_id=prompt.id,
                     prompt_version=prompt.version, model_version=answer.model)
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers ai features playbook: https://agentwranglers.se/playbook/ai-features/prompts-as-code/prompt-version-in-logs`.

- Previous: [Review and test every prompt change](https://agentwranglers.se/playbook/ai-features/prompts-as-code/prompt-change-review)
- Next: [Show the model worked examples](https://agentwranglers.se/playbook/ai-features/prompts-as-code/worked-examples)
- [Prompts as code](https://agentwranglers.se/playbook/ai-features/prompts-as-code)
