Why it matters
Ad-hoc prompt strings are hard to maintain. Templates make prompts first-class artifacts: versioned, testable, and reusable. This is basic engineering hygiene for LLM apps.
The architecture
Template: prompt text with placeholders like {{variable}}. Rendered with actual values at runtime.
Template engine (Jinja, Handlebars, or built-in): substitutes placeholders, supports conditionals and loops.
How it works end to end
Version control: check templates into Git. Diff prompt changes over time. Roll back regressions.
Testing: evaluate templates in CI. Prompt changes are code changes; treat with same rigor.
Composition: templates can include other templates. Build libraries of reusable prompt components.
Separation: keep templates separate from application code. Enables non-engineers to iterate on prompts.