---
title: "Prompts as code · Agent Wranglers"
url: https://agentwranglers.se/playbook/ai-features/prompts-as-code
updated: 2026-10-20
licence: "All rights reserved"
---

# Prompts as code

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

> Keep every prompt in a versioned file and user text apart from instructions. No prompt change ships without review and a passing eval run.

**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`.

## Required

- [Keep prompts in files](https://agentwranglers.se/playbook/ai-features/prompts-as-code/prompts-in-files): Store every prompt as a template file in version control, one file per prompt, with an ID and a version. Never build prompts from strings scattered through the code.
- [Keep user text out of the instructions](https://agentwranglers.se/playbook/ai-features/prompts-as-code/user-text-apart): Put user input and retrieved documents in their own message or a clearly marked block. Never paste them into the system instructions.
- [Review and test every prompt change](https://agentwranglers.se/playbook/ai-features/prompts-as-code/prompt-change-review): Treat a prompt change like a code change. It goes through review, and the feature's eval set must pass before it merges.
- [Log which prompt made each answer](https://agentwranglers.se/playbook/ai-features/prompts-as-code/prompt-version-in-logs): Record the prompt ID, prompt version and exact model version with every model call and every stored AI output.

## Recommended

- [Show the model worked examples](https://agentwranglers.se/playbook/ai-features/prompts-as-code/worked-examples): Include two to five worked examples of input and the expected output in prompts where format or tone matters. Keep them in the prompt file and out of the eval set.

- Previous: [Deciding to use a model](https://agentwranglers.se/playbook/ai-features/deciding-to-use-a-model)
- Next: [Structured output and tools](https://agentwranglers.se/playbook/ai-features/structured-output-and-tools)
- [All chapters](https://agentwranglers.se/playbook/ai-features)
