The prompt is the instruction for the LLM, usually sent in plain-text or an array of chat-style messages. When working with certain models, the prompt is formatted like chat messages, allowing you to control a system message, user message, and assistant message.

llm-exe provides a prompt interface to simplify working with prompts. Ultimately a prompt is a string, but building elaborate prompts can quickly get complicated. The prompt utility provides a foundation for building complex prompts.

  • Support for text-based or chat-based prompts.
  • Uses Handlebars as template engine, allowing you to use features such as custom templates, partials, functions, etc. See handlebars documentationopen in new window for everything you can do.
  • Infers types when they are provided.

Note: You can use and call methods on prompts directly, but they are usually passed to an LLM executor and then called internally.

There are 2 types of prompts included, along with a BasePrompt class that can be extended, if needed.


Basic Replacements

The object that you pass to prompt.format (or .execute when a prompt is part of an LLM executor) gets passed to the template engine, making all those variables available to you in your prompt template.

const instruction = `You are a customer service agent for Some Company.

Your name is {{agentName}}.`

const prompt = createPrompt("text", instruction)

const formatted = prompt.format({ agentName: "Greg" })
You are a customer service agent for Some Company.

Your name is Greg.

For advanced uses and working with custom helpers/partials, see here.

Using Types with Prompts

// Example 2
interface SomePromptInput {
    agentName: string;

const prompt = createChatPrompt<SomePromptInput>("Your name is {{agentName}}");

// @ts-ignore (for example)
// Bad. Incorrect input, Typescript error.
// Argument of type '{ name: string; }' is not assignable to parameter of type 'SomePromptInput'.
prompt.format({name: "Greg" })

// Good: No problem, correct inputs
prompt.format({agentName: "Greg"})
  "type": "chat",
  "messages": [
      "role": "system",
      "content": "Your name is {{agentName}}"
  "partials": [],
  "helpers": [],
  "parseUserTemplates": false
Last Updated:
Contributors: Greg Reindel