Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/simonw/LLM/llms.txt

Use this file to discover all available pages before exploring further.

Templates bundle a prompt, system prompt, model, default options, schema, tools, and fragments into a single named unit that you can invoke with -t template-name. They are stored as YAML files on disk and use Python’s string.Template $variable syntax so the same template can accept different inputs at runtime.

Creating a Template with --save

The quickest way to create a template is to build your prompt normally and add --save name:
llm '$input - summarize this' --save summarize
Use $input as a placeholder for content passed by the user (piped via stdin or as a CLI argument). If you omit $input, LLM appends the user’s input after your prompt automatically.
llm --system 'Summarize this' --save summarize
To include a literal $ in your prompt, escape it as $$.

Using a Template

Execute a template with -t / --template:
curl -s https://example.com/ | llm -t summarize
Override the model at runtime:
curl -s https://llm.datasette.io/en/latest/ | \
  llm -t summarize -m gpt-3.5-turbo-16k
Load a template directly from a file path or URL:
# From a local YAML file
llm -t path/to/template.yaml 'extra prompt here'

# From a URL
llm -t https://raw.githubusercontent.com/simonw/llm-templates/refs/heads/main/python-app.yaml \
  'Python app to pick a random line from a file'
Templates loaded from URLs have their functions: key ignored to prevent arbitrary code execution.

Listing and Editing Templates

# List all templates
llm templates

# Open a template in your $EDITOR
llm templates edit summarize

# Find the templates directory
llm templates path
Example llm templates output:
cmd    : system: reply with macos terminal commands only, no extra information
glados : system: You are GlaDOS  prompt: Summarize this:
Set the EDITOR environment variable to control which editor opens. For VS Code: export EDITOR="code -w".

Template YAML Format

Templates are YAML files. Every key is optional — include only what you need.

Minimal template

prompt: 'Summarize this: $input'

Full example

name: steampunk-summary
model: gpt-4o
system: You speak like an excitable Victorian adventurer
prompt: >
  Summarize the following text.

  Insert frequent satirical steampunk-themed anecdotes.

  Text to summarize: $input
options:
  temperature: 0.9
extract: false

Key reference

KeyDescription
promptThe user prompt. Use $input for user-supplied content.
systemSystem prompt (higher-weight instructions).
modelDefault model ID for this template.
optionsMap of model option names to default values.
schema_objectEmbedded JSON schema (as YAML) for structured output.
toolsList of tool names or toolbox specifiers.
functionsMulti-line Python code string defining callable functions.
fragmentsList of fragment URLs, file paths, or hashes for the user prompt.
system_fragmentsSame as fragments but injected into the system prompt.
extracttrue to extract the first fenced code block from responses.
defaultsMap of variable names to default values.

System prompts

system: Summarize this
When only a system prompt is set, the entire user input becomes the regular prompt.

Combining system and prompt

system: You speak like an excitable Victorian adventurer
prompt: 'Summarize this: $input'

Fragments in templates

fragments:
  - https://example.com/robots.txt
  - /path/to/file.txt
  - 993fd38d898d2b59fd2d16c811da5bdac658faa34f0f4d411edde7c17ebb0680
system_fragments:
  - https://example.com/system-prompt.txt

Tools in templates

tools:
  - llm_time
  - 'Datasette("https://example.com/timezone-lookup")'
functions: |
  def reverse_string(s: str):
      return s[::-1]

  def greet(name: str):
      return f"Hello, {name}!"

Schemas in templates

schema_object:
    properties:
        dogs:
            items:
                properties:
                    bio:
                        type: string
                    name:
                        type: string
                type: object
            type: array
    type: object

Template Variables

Beyond $input, you can define any number of named variables that callers must supply with -p / --param:
# recipe template
prompt: |
  Suggest a recipe using ingredients: $ingredients

  It should be based on cuisine from this country: $country
llm -t recipe -p ingredients 'sausages, milk' -p country Germany

Default Parameter Values

Store defaults in the YAML:
system: Summarize this text in the voice of $voice
defaults:
  voice: GlaDOS
Or set them when saving:
llm --system 'Summarize this text in the voice of $voice' \
  --model gpt-4o -p voice GlaDOS --save summarize
The default is used automatically; override it at runtime with -p:
# Uses GlaDOS (default)
curl -s https://example.com/ | llm -t summarize

# Override with Yoda
curl -s https://example.com/ | llm -t summarize -p voice Yoda

Template Loaders from Plugins

Plugins can register URL-style prefixes to load templates from external sources. Install llm-templates-github to load templates from GitHub:
llm install llm-templates-github
List all registered loaders:
llm templates loaders
Example output:
gh:
  Load a template from GitHub or local cache if available

  Format: username/repo/template_name (without .yaml extension)
    or username/template_name which means username/llm-templates/template_name
Use it:
curl -sL 'https://llm.datasette.io/' | llm -t gh:simonw/summarize
If two plugins register the same prefix, one will have _1 appended. Check llm templates loaders to inspect the mapping.

Build docs developers (and LLMs) love