Agent Wranglers

AIF-9Recommended

Log which prompt made each answer

Record the prompt ID, prompt version and exact model version with every model call and every stored AI output.

How to do it

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. Add it as a field of a structured log event.

Examples

SQL example

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

TypeScript example

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

Python example

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

How to 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.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/prompts-as-code/prompt-version-in-logs">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.