prompt-template-lite
v0.1.0
Published
Lightweight prompt templating with {{var}} interpolation and version tracking, so you know which prompt version produced which LLM output.
Maintainers
Readme
prompt-template-lite
Lightweight prompt templating with {{var}} interpolation and version tracking — so logs and evals can record exactly which prompt version produced which LLM output.
Install
npm install prompt-template-liteQuick start
import { defineTemplate } from 'prompt-template-lite';
const summarize = defineTemplate('Summarize this in {{sentences}} sentences:\n{{text}}', { version: 'v3' });
const { text, version } = summarize.render({ sentences: 2, text: doc });
// log `version` alongside the LLM response so you can trace which prompt produced itMissing a required variable throws immediately instead of silently rendering {{name}} into the prompt:
summarize.render({ text: doc }); // Error: Missing required template variable: "sentences"Why version tracking matters
Prompt text changes constantly during development, and a model's behavior shifts with it. Without recording which exact prompt version produced a given output, you can't tell whether a regression in an eval run came from a model change, a prompt edit, or noise. defineTemplate auto-derives a version hash from the template text (or accepts an explicit one), and every render result carries it — cheap enough to log on every call.
API
defineTemplate(template, options?)— returns aPromptTemplatewith.render(vars),.version,.source.render(vars)— throws if a required{{var}}is missing, otherwise returns{ text, version }
License
MIT
