# Prompt Templates, Versioning and Iteration

> Treat prompts as code: templates with variables, version control, change reviews and a repeatable loop for improving them. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/ai-engineer/prompt-management
Last updated: 2026-11-28

Treat prompts as code: templates with variables, version control, change reviews and a repeatable loop for improving them.

Intermediate · about 3 hours · difficulty 2/5

Learn first: [Structured Prompts and Long Context](https://www.internhack.in/roadmaps/tracks/ai-engineer/structured-prompts), [Git and Project Hygiene](https://www.internhack.in/roadmaps/tracks/ai-engineer/git)

Once an app has more than two prompts, ad hoc strings scattered through the code become a liability. Nobody knows which version is live or why a behaviour changed.

### Practices

- **Templates**: store prompts as files or constants with named variables (Jinja, f-strings, or a template library). Keep business logic out of the template.
- **Version control**: prompts live in Git with the code, or in a prompt registry that records versions. Every production response should be traceable to a prompt version.
- **Review changes like code**: a prompt diff can change behaviour for every user. Require a test run before merging.
- **Iteration loop**: collect failing examples, form a hypothesis, change one thing, rerun the test set, keep or revert.
- **Model-specific tuning**: a prompt tuned for one model family may need adjustments for another. Record which model a prompt was validated with.

### Tools

Prompt playgrounds in provider consoles are good for exploring. Observability platforms like Langfuse and LangSmith offer prompt registries linked to traces. Tools like promptfoo let you run a prompt against a test matrix from the command line. The evaluation section builds on this.

### Pitfalls

Endless tweaking without measurement. If you cannot say whether version 7 beats version 6 on a test set, you are guessing.

### Good enough to move on

Your project has prompts in versioned template files, and you can rerun a fixed test set after any prompt change.

## Key concepts

- **Prompt templates with variables**
- **Versioning prompts in Git**
- **Prompt registries**
- **Test-driven prompt iteration**
- **promptfoo**
- **Per-model prompt variants**

## Mini project

Refactor an existing app so all prompts live in versioned template files, log the prompt version with each response, and add a script that runs a 20-case test set against any prompt version.

## Check yourself

A user complaint arrives about an answer from two weeks ago. What would you need to have logged to reproduce it exactly?

## Free resources

- [promptfoo documentation](https://www.promptfoo.dev/docs/intro/) (promptfoo)
- [Langfuse prompt management](https://langfuse.com/docs) (Langfuse)

Previous: [Structured Prompts and Long Context](https://www.internhack.in/roadmaps/tracks/ai-engineer/structured-prompts) · Next: [Text Embeddings](https://www.internhack.in/roadmaps/tracks/ai-engineer/embeddings)

## More in Prompt Design That Holds Up

- [Clear Instructions and System Prompts](https://www.internhack.in/roadmaps/tracks/ai-engineer/prompt-fundamentals)
- [Few-Shot Examples](https://www.internhack.in/roadmaps/tracks/ai-engineer/few-shot-prompting)
- [Chain-of-Thought and Task Decomposition](https://www.internhack.in/roadmaps/tracks/ai-engineer/chain-of-thought)
- [Structured Prompts and Long Context](https://www.internhack.in/roadmaps/tracks/ai-engineer/structured-prompts)
- [Prompt Templates, Versioning and Iteration](https://www.internhack.in/roadmaps/tracks/ai-engineer/prompt-management)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [AI Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/ai-engineer)
