Skip to content

Chapter 7 · Templates

Templates solve a different problem than scripts: not "is the computation right?" but "is the output shaped the same way every time?" A template is the contract for the artifact — the skeleton the agent fleshes out, so reports, changelogs, PR descriptions, and configs come out consistent no matter which run, which model, or which teammate produced them.

Where templates live

The spec's convention is the assets/ directory: static resources the skill uses rather than reads as instructions — document templates, configuration templates, schemas, fixtures, images.

changelog-forge/
├── SKILL.md
├── assets/
│   └── changelog_template.md   # the output contract
└── scripts/
    └── generate_changelog.py   # fills the mechanical parts

The distinction from references/ is direction of flow: references are input to the model's thinking; assets are input to the output itself.

Placeholder conventions

Keep placeholders impossible to miss and impossible to confuse with real content:

## [{{VERSION}}] — {{DATE}}

### Added
{{ADDED}}

### Fixed
{{FIXED}}
  • SCREAMING_CASE with double braces — {{VERSION}}, {{SECTION_ADDED}}. No model will mistake that for prose, and a final grep {{ catches any the agent failed to replace.
  • One placeholder per section, not per sentence. If you write {{SENTENCE_ABOUT_X}}, you're scripting prose — that's the model's job. Templates shape; the agent writes.
  • Self-checking. End the workflow with a mechanical check: grep -n "{{" output.md must return nothing before the artifact ships. (Or fold it into the validation script from chapter 6.)

The boundary: script-filled vs model-filled

The highest-leverage use of templates is the one where a script fills the mechanical parts and the agent fills the judgment parts, and the template marks the boundary between them.

examples/changelog-forge/ does exactly this:

flowchart LR
    A["git history"] --> B["Script:<br>categorize commits,<br>render sections"]
    B --> C["Draft with<br>raw commit bullets"]
    C --> D["Agent rewrites:<br>human phrasing, dedupe,<br>drop noise"]
    D --> E["grep {{<br>no placeholders left"]
  1. The script runs git log, parses Conventional Commit types, categories them into Added / Changed / Fixed / Breaking, and renders the template with - <hash> <subject> bullets. Deterministic: same repo state, same draft.
  2. The agent rewrites the bullets into human prose — merging duplicates ("fix: typo, fix: another typo" → one entry), dropping noise ("chore: release v1.2.2"), translating commit-shorthand into user-facing language.
  3. A final mechanical check ensures no placeholder survived.

Neither half could do the job alone: the script guarantees completeness (every commit since the last tag is accounted for), the agent guarantees readability. This script-fills-skeleton / agent-writes-content pattern is the single best use of templates.

Template patterns in the wild

Pattern Template contains Agent fills in
Document/report Section headings, order, required fields The analysis and prose
Config scaffold Full file with commented options Environment-specific values
Code scaffold File tree, module skeletons, docstring placeholders Implementation bodies
PR description Summary / Changes / Test plan / Risks sections The content of each section
Data schema Table columns, types, constraints The actual data
Release notes Categories (chapter example) Polished entries per category

SKILL.md wiring

The template only works if the workflow references it and enforces it:

## Workflow

1. Generate the mechanical draft:
   python scripts/generate_changelog.py --since <last-tag> --stdout
2. Rewrite each bullet for humans: merge duplicates, drop chore/release
   noise, describe impact rather than mechanics.
3. Render the final entry into [assets/changelog_template.md](assets/changelog_template.md)
   structure — keep the section order and headings exactly.
4. Check no placeholder survived: grep -n "{{" CHANGELOG.md must be empty.

Note step 3's phrasing: keep the section order exactly. Without it, models creatively "improve" your format. Consistency is the point of the template — say so out loud.

Anti-patterns

The fill-in-the-blanks essay

Twenty {{...}} placeholders inside sentences. The template becomes a Mad Libs and the output reads like one. Shape sections, not sentences.

The buried template

A template pasted into the SKILL.md body that the agent must find and mentally extract. Put it in assets/ where the workflow can say "render into this file's structure" — and the script can read it directly.

The optional structure

"You may add sections if relevant" — now every run differs and nobody can grep the output. If a section is conditional, encode the condition in the script or make the agent state why it's omitted.


Chapter 8 · Memory & State — teaching your skill to remember.