Lesson 6 / 25

Template Hygiene: Variables, Versions and Length

Prompts are code; treat them that way.

Render, measure, version

Production prompts are templates with variables (user input, retrieved context, settings). Check that every variable is filled (an empty variable silently changes the prompt), that rendered prompts stay within a token budget, and that the stable part comes first (better for caching). Give each template a version id, store it in version control, and record which version produced each output so scores and complaints can be traced.

Template checks to automate

Run them when rendering in tests.

check                                     why
all {{variables}} filled, none empty       empty values silently change behaviour
rendered tokens <= budget                  long prompts cost more and can truncate
stable instructions before variable data  prompt caching works on prefixes
input wrapped in delimiters                reduces instruction/data confusion
version id logged with every output        trace scores and complaints to a version

Render with edge-case inputs

Test templates with empty, very long and unusual inputs to see the actual prompts the model will receive.

Quick check: Why log the prompt version with every output?

  • It improves output quality automatically
  • To make prompts shorter
  • Models require version ids
  • So scores and complaints can be traced to a specific version
Answer

So scores and complaints can be traced to a specific version — Versioning enables comparison and rollback.