Files

Prompt template renderer that fails on missing variables (Node.js)

A zero-dependency Node.js script that fills {{variable}} placeholders in a prompt file from JSON, supports nested keys and lists, and exits non-zero on missing or unused variables so broken prompts never reach a model.

File in Engineering by AISkillHub Library

What it does

Simple string replacement is how most prompt templates are filled, and it fails silently: a renamed variable leaves `{{customer_name}}` in the text the model receives, and nobody notices until outputs get strange. This renderer is strict by default.

**What it does**

- Replaces `{{name}}` and dotted paths such as `{{product.name}}` with values from a JSON file or stdin. - Strings go in as-is. Arrays of strings become a `- item` list. Other objects and arrays are inserted as pretty-printed JSON. Numbers and booleans are converted to text. - Removes a `--- ... ---` front matter block from the output, so prompts can carry metadata. - `\{{` produces a literal `{{` for prompts that need to show template syntax. - **Fails** with exit code 1 when a placeholder has no value, or when the JSON has keys the template never uses (catches renamed variables from the other side). Use `--allow-unused` to relax the second rule. - `--check` validates without printing; with no vars file it lists the template's variables, which is handy for generating forms or docs.

**Example**

The listing includes `prompts/release-notes.md` and a matching `release-notes.vars.json`:

``` $ node scripts/render-prompt.mjs prompts/release-notes.md prompts/release-notes.vars.json You write release notes for Acme Invoicing, a product used by finance teams at small companies. ... <changes> - feat: export invoices as CSV from the list view - fix: PDF totals rounded wrong when tax rate had three decimals ... ```

Pipe the output into any CLI or API call, or use `--out rendered.md`.

**What it will not do**

No conditionals, loops or filters. If you need those, you need a full template engine; this tool is for plain fill-in prompts where strictness matters more than features.

Exit codes: 0 rendered or check passed, 1 missing or unused variables, 2 usage error (unreadable file, invalid JSON).

How to use it

1. Copy `scripts/render-prompt.mjs` into your repository. The example files `prompts/release-notes.md` and `prompts/release-notes.vars.json` are optional. 2. Requires Node.js 18 or newer. No `npm install` needed. 3. Use it: ``` node scripts/render-prompt.mjs prompts/release-notes.md prompts/release-notes.vars.json node scripts/render-prompt.mjs prompts/release-notes.md vars.json --out rendered.md node scripts/render-prompt.mjs prompts/release-notes.md --check # list variables node scripts/render-prompt.mjs prompts/release-notes.md vars.json --check # validate only echo '{"version":"2.4.0"}' | node scripts/render-prompt.mjs prompts/x.md - --allow-unused ``` 4. In the example template, `{{product.name}}`, `{{product.audience}}`, `{{previous_version}}`, `{{version}}` and `{{changes}}` are the variables to fill; `changes` takes a list of strings. 5. Add `--check` runs to CI for each template and its sample vars file to catch drift.

No environment variables or secrets.

Files

Save each file at the path shown, relative to your project root.

  • prompts/release-notes.md730 B
  • prompts/release-notes.vars.json406 B
  • scripts/render-prompt.mjs5.3 KB

More files

See all
  • File· OperationsFree

    Postmortem template for AI and LLM feature incidents

    A blameless incident postmortem template adapted for AI features: records model and prompt versions, user and data impact, agent actions taken, an AI-specific failure classification, layered root cause questions, and eval-focused action items.

    ChatGPTClaudeGeminiCoding agents

    ALAISkillHub Library

  • File· EngineeringFree

    GitHub Copilot instructions for FastAPI, SQLAlchemy 2.0 and Pydantic v2

    A .github/copilot-instructions.md that steers Copilot toward current FastAPI patterns: SQLAlchemy 2.0 select() style, Pydantic v2 APIs, thin routers with service layers, per-record authorization checks, and pytest with dependency overrides.

    Coding agents

    ALAISkillHub Library

  • File· EngineeringFree

    CLAUDE.md template for Laravel applications

    A ready-to-fill CLAUDE.md for Laravel projects that gives Claude Code the commands, conventions and guardrails it needs: tests with Pest or PHPUnit, Pint, migrations, Form Requests, policies, queues and config caching rules.

    Coding agentsClaude

    ALAISkillHub Library

Get AISkillHub updates in your inbox.

New features as they ship, AI live chat improvements, and the best new listings in the catalog.

Product updates, new features, and guides. Unsubscribe any time.