Aerostack
memory

ai-prompt-template Edge Function — Ai

AI

Fills {{variable}} placeholders in a prompt template string, with optional strict mode to catch missing variables.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function ai-prompt-template Fills {{variable}} placeholders in a prompt template string, with optional strict mode to catch missing variables.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/ai-prompt-template
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "ai-prompt-template",
  args: {
    "template": "example_template",
    "variables": null,
    "strict": true
  }
})

ai-prompt-template — Fill prompt templates with dynamic variables

Replaces {{variableName}} placeholders in a prompt template string with supplied values, with optional strict mode to catch missing variables before sending to an LLM.


API

POST /api/ai-prompt-template

Request body

Field Type Required Default Description
template string Prompt string containing {{variableName}} placeholders
variables object Key-value map of placeholder names to replacement values (string, number, boolean)
strict boolean true If true, throw when any placeholder is unresolved

Success response (200)

{
  "success": true,
  "data": {
    "prompt": "Hello, Alice! Your task is to summarize the document.",
    "resolvedCount": 2,
    "unresolvedPlaceholders": []
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 Missing required field or wrong type
INTERNAL_ERROR 500 Unresolved placeholder in strict mode

Usage

cURL
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "Hello, {{name}}! Your task is to {{task}}.",
    "variables": { "name": "Alice", "task": "summarize the document" }
  }'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    template: 'Translate the following to {{language}}:\n\n{{text}}',
    variables: { language: 'French', text: 'Good morning!' },
  }),
});
const { data } = await response.json();
console.log(data.prompt);
Direct import (Node / Bun / Deno)
import { aiPromptTemplate } from '@aerostack/functions/ai-prompt-template';

const result = aiPromptTemplate({
  template: 'You are a {{role}}. Answer the following: {{question}}',
  variables: { role: 'helpful assistant', question: 'What is RAG?' },
});
console.log(result.prompt);

Use Cases

  • Building a prompt library where each entry uses {{placeholders}} for user-supplied data before sending to an LLM API.
  • Generating personalised email drafts or support replies by filling in customer name, product, and issue variables.
  • Validating prompt templates during CI — set strict: true and check that all placeholders resolve before deploying.

Notes

  • Placeholder syntax is {{variableName}} — double curly braces, alphanumeric + underscores only.
  • Values are coerced to strings; numbers and booleans are supported.
  • When strict: false, unresolved placeholders are left as-is in the output and listed in unresolvedPlaceholders.
  • Consecutive blank lines in the resolved prompt are collapsed to a maximum of two.

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

ai
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More AI Functions

Browse AI Functions →

Frequently asked questions

What does the ai-prompt-template function do? +

ai-prompt-template is a serverless edge function for ai automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the ai-prompt-template function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/ai-prompt-template ``` It will be live on Cloudflare Workers in seconds.

What runtime does ai-prompt-template use? +

ai-prompt-template runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the ai-prompt-template function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.