prompt-library: versioned prompt templates for WordPress

A WordPress plugin that stores prompt templates with typed variables as immutable numbered versions, renders them for other plugins by slug, and offers a capped test runner.

prompt-library is a WordPress plugin for people who keep prompts for language models. Templates have named, typed variables and are published as immutable numbered versions. Other plugins fetch and render a template by slug and version, so a wording change no longer needs a code change and a deploy. The code is at https://github.com/IndianOpinion/prompt-library, licensed MIT. Version v0.1.0 was released on 15 November 2026.

We wrote it from scratch from a one-line idea. Its PRD says plainly that it was not extracted from running code, and it has not run on a live site. The 47 utilities in this series were specified, built, reviewed and released between 11 and 19 November 2026 by language-model coding agents under the editor’s direction, in five roles: a spec writer, a spec reviewer, a builder that saw only the spec, an independent code reviewer and a releaser. The editor made the rulings on every open question.

The problem

Plugins that call language models keep their prompts as string literals in PHP. Every wording change is a code change. Nobody can see which wording produced which output last Tuesday. Editors who own the wording cannot change it, and engineers who can change it cannot easily try it. When a prompt is built by string concatenation, a value that contains a section’s closing marker or a stray placeholder silently changes the prompt’s meaning.

The opposite mistake is to keep prompts as ordinary posts. They then pass through display filters that turn straight quotes curly, add paragraph tags, run shortcodes and strip markup for users without the unfiltered HTML capability. A prompt saved and read back is no longer the prompt that was written.

What it does

  • Stores each template as a post of a private post type, edited in plain monospace textareas.
  • Validates a strict placeholder syntax: {{ name }} only, with no filters, defaults, dots or expressions.
  • Declares variables with a type (string, text, integer, number, boolean, enum, list, json), a length limit and an escape mode.
  • Publishes immutable numbered versions with a required note, and moves a live pointer. Rollback is “Make live” on an older version.
  • Renders for other plugins by slug, with a version number, live or latest.
  • Offers a test runner that shows the rendered prompt and the model’s answer side by side, and a free Preview that never calls a model.
  • Exports and imports templates as JSON, and has REST routes and WP-CLI commands.

How it works

The draft lives in one post meta value and post content stays empty, so no content filter, shortcode, autop, texturize or kses pass touches prompt text. Published versions are rows in their own table, not WordPress revisions, because sites limit or disable revisions and a version a consumer depends on must never disappear. A unique key on template and version number makes a duplicate number impossible. Each version stores a SHA-256 content hash, and a render recomputes it and compares.

The parser, renderer and value objects have no WordPress dependency. Rendering is one left-to-right pass, so a value that contains {{ other }} stays literal text. Checks run in a fixed order: types, defaults, required values, lengths, escaping, substitution, total size. Each stage lists every problem it finds, and nothing partial is ever returned. An uncached render costs two queries.

The escape modes are plain (strips control characters, bidirectional overrides and the byte order mark, but keeps the zero-width joiner and non-joiner that Indic scripts need), raw, line, json and fenced. A fenced value goes between <name> and </name> lines, and any closing tag inside the value is rewritten so the value cannot close its own fence.

$prompt = promptlib_render('article-summary', [
    'title' => $post->post_title,
    'text'  => wp_strip_all_tags($post->post_content),
], 'live', ['consumer' => 'my-plugin']);

$messages = $prompt->toMessages(); // system first, then user

A plugin that does not want a hard dependency uses the promptlib_render filter instead. It returns null when prompt-library is inactive, so the caller falls back to its own text.

Guard rails

  • The test runner is the only thing that calls a model. Its order is fixed: kill switch, permission and nonce, render, the plugin’s own daily caps, the spend-meter check, the call, the report, settling cost, the run row.
  • The daily runs cap defaults to 50 and a cap of 0 allows no runs. A cost cap is off until set. The runs cap is reserved with one conditional increment, so two requests at the cap cannot both pass.
  • PROMPTLIB_DISABLE_RUNNER wins over the setting. Preview still works.
  • When spend-meter is active, every attempt is checked first and reported afterwards. A meter that throws, returns a malformed decision or speaks an unknown contract version stops the run. A broken meter must not mean unmetered spend.
  • Values over their max_length throw. Nothing is truncated silently.
  • The provider key setting is write-only and never appears in REST responses, exports, logs or run rows.
  • Escaping reduces prompt injection and does not prevent it. The README says so.

What review changed

The independent code review changed these before the merge:

  • A gateway that throws (for example a site-supplied client) escaped the runner and skipped the reporting and run-row steps. It is now caught, logged, recorded as a failed run, and its spend-meter reservation is released.
  • In compare mode, if the first selection threw, the second selection’s reservations were left held. They are now given back.
  • A run row that cannot be stored no longer hides a paid answer behind a storage error.
  • Fallback attempts are now checked against the daily cost cap, counting what the run already spent.
  • The history “live” row is written before the pointer moves, so a failed history write no longer leaves the live version changed with no record.

Limits and what is next

  • No logic in templates: no conditionals, loops, includes or filters.
  • No streaming, images, audio, tools or function calling in the runner, and no automatic scoring.
  • No per-locale variants of a template in 0.1.0.
  • Not a must-use plugin in 0.1.0, because activation creates tables and capabilities.
  • Pre-call token counts are an estimate: characters divided by four.
  • One open issue: a failed version insert during import can leave a template with versions and no live pointer. The proposed fix marks the template incomplete without deleting any rows, lets the operator repair it, and makes rendering it fail with a typed exception.

Test status: this is v0.1.0. 175 PHPUnit tests run without WordPress on a stub layer, with a fake database that simulates a skipped column add and a unique-key race. Static analysis and code style checks passed. Per-site table isolation on multisite needs a real WordPress test install and was not covered. CI has not yet run on GitHub: the commit adding the workflow stayed local because the token lacked the workflow scope.

Install

It needs WordPress 6.4 or later, PHP 8.1 or later, and the mbstring and json extensions. The test runner needs Composer, to fetch llm-json-php, the only runtime dependency.

cd wp-content/plugins
git clone https://github.com/IndianOpinion/prompt-library.git
cd prompt-library
composer install --no-dev

Without Composer, templates, versions, rendering, import and export still work. The test runner stays off, with a notice.

All 47 utilities · prompt-library on GitHub

Search Trending
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...

All fields are required.