Prompt Templates, Versioning and Testing: Making Prompts Reusable and Reliable in Real Apps

LLM Development 55 min min read Updated: Nov 21, 2026 Intermediate
Prompt Templates, Versioning and Testing: Making Prompts Reusable and Reliable in Real Apps
Intermediate Topic 3 of 3

Why Templates?

In a real app the same prompt is used thousands of times with different data. A template has fixed text and placeholders for the changing parts.

python from string import Template SUMMARY_V1 = Template("Summarize the text below in $n bullet points for a $audience.\n\nText:\n$text") print(SUMMARY_V1.substitute(n=2, audience="busy manager", text="Sales grew 10% in Q3 after the new campaign."))
Result

Summarize the text below in 2 bullet points for a busy manager. | | Text: | Sales grew 10% in Q3 after the new campaign.

Version Your Prompts

  • Give each prompt a name and a version such as summary_v2
  • Store prompts in files or a repository, not hidden in code
  • Write down why you changed it
  • Keep old versions so you can roll back

Write Simple Tests

You cannot test an LLM answer exactly, but you can test rules an answer must follow. Build a small set of inputs and check the output with simple functions.

python import json def fake_model(prompt): # stands in for a real call, so the demo always runs return '{"sentiment": "positive", "confidence": 0.9}' def check(output): problems = [] try: data = json.loads(output) except Exception: return ["not valid JSON"] if data.get("sentiment") not in {"positive", "negative", "neutral"}: problems.append("bad sentiment value") if not 0 <= data.get("confidence", -1) <= 1: problems.append("confidence out of range") return problems tests = ["Great product!", "Terrible service", "It is fine"] for t in tests: out = fake_model(t) print(t, "->", check(out) or "OK")
Result

Great product! -> OK | Terrible service -> OK | It is fine -> OK

In real use, replace fake_model with your API call and run the tests each time you change a prompt. This is a regression test: it warns you when a change breaks something that used to work.

What to Check

CheckExample
FormatValid JSON, correct keys
LengthUnder 50 words
Must includeContains the order number
Must not includeNo email addresses, no profanity
QualityCompare with a reference answer or use a rubric
Grow the test set Every time a user finds a bad answer, add it to the test set.
Escaping user text Never trust user text inside a template. It may contain instructions that try to change your prompt. You will study this in the security lessons.

Practice

  1. Make a template with three placeholders
  2. Write five test inputs and a check function
  3. Change the prompt and rerun the checks

Conclusion

Templates, versions and tests make prompts dependable parts of your software.

Quick Summary: Templates; versioning; rule-based tests; regression tests.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators