Template Syntax
A template is the section of a prompt file following the Frontmatter.
---
# Frontmatter: YAML configuration
input:
schema:
param1: type, description
param2?: type, optional description
---
Your templated prompt here with {{param1}} and {{param2}}.Templates uses Handlebars syntax for dynamic content generation based on the input schema and available helpers.
Template Basics
Within a template you will primarily make use of the parameters defined in your input schema.
Variable Substitution
The simplest usage is direct variable substitution where you directly render the inputs:
---
input:
schema:
lang: string, Target language
text: string, Text to translate
---
Translate the following text to {{lang}}:
{{text}}Conditionals
You might also want to conditionally render parts of the template based a boolean input, or whether an optional parameter has been set:
---
input:
schema:
lang: string, Target language
source-lang?: string, Source language, leave blank to auto detect
text: string, Text to translate
summarize?: boolean, Wheter to also summarize the text
---
{{#if source-lang}}
Translate the given text from {{source-lang}} to {{lang}}
{{else}}
Translate the given text to {{lang}}
{{/if}}
{{#if summarize}}
Produce a summarized version of the translation.
{{/if}}
Here is the text:
{{text}}Comments
Add comments that won't be included in the generated prompt:
Standard Input (stdin)
Standard Input is accessible via the stdin helper:
---
input:
schema:
lang: string, Target language
text?: string, Text to translate, will default to stdin if not given
---
Translate the following text to {{lang}}:
{{#if text}}
{{text}}
{{else}}
{{stdin}}
{{/if}}Helpers
Template helpers enable customizations in templates that go beyond basic variable substitution.
Basic Helpers
{{#if words}}...{{/if}}: Conditional logic using Handlebars
| Syntax | Description |
|---|---|
{{{{raw}}}}..{{{{/raw}}}} | Print enclosed Handlebars expressions without rendering |
{{#if ..}}..{{else}}..{{/if}} | Conditionally render blocks |
{{#unless ..}}..{{else}}..{{/unless}} | Conditionally render blocks (if not) |
{{eq a b}} | Check if a = b, renders to true or false |
{{ne a b}} | Check if a != b, renders to true or false |
{{gt a b}} | Check if a > b, renders to true or false |
{{gte a b}} | Check if a >= b, renders to true or false |
{{lt a b}} | Check if a < b, renders to true or false |
{{lte a b}} | Check if a <= b, renders to true or false |
{{and a b}} | Boolean "And", renders to true if both a and b are true |
{{or a b}} | Boolean "Or", renders to true if either a or b is true |
{{not a}} | Boolean "Not", renders to true or false, the inversion of a |
You may use Boolean and Comparison expressions within conditional expressions:
Remote-Capable Helpers
some helpers below are annotated with remote-capable. These are helpers whose behaviour change depending on whether the prompt is executing locally, or in a remote execution context such as SSH. The remote-context behaviour of each is described under each helper.
Non-remote capable helpers execute just fine in remote contexts, just without remote-dependant behaviour.
String Concatenation
Concatenate any number of strings together using the concat helper.
Exec Helper remote-capable
The exec helper enables execution of raw commands and inserting the output inline in your prompt. Both stdin and stderr are captured.
---
input:
schema:
repo: string, The github repository name
branch?: string, Branch name, defaults to "main"
---
You are a github README assistant. Your task is to summarize a given README file,
indicating very briefly what the repo is about and installation instructions.
Here is the README:
{{#if branch}}
{{exec "curl" "-LsSf" (concat "https://raw.githubusercontent.com/" repo "/refs/heads/" branch "/README.md")}}
{{ else }}
{{exec "curl" "-LsSf" (concat "https://raw.githubusercontent.com/" repo "/refs/heads/main/README.md")}}
{{/if}}INFO
When executed in a remote context, the command is executed on the remote host rather than on the local machine.
Prompt Helper
The prompt helper enables execution of other prompt files and inlining the output within the current prompt, in other words; nested prompting.
---
input:
schema:
container: string, container name
---
Analyze the following logs and let me know if there are any problems:
{{exec "docker" "logs" container}}Ask Helper
The Ask Helper enables interactively querying input from the user during execution time. In the following example, the URL used in curl is created from interactively querying the user for the repo name via (ask "Repo: " ), and branch name via (ask "Branch: " ).
---
---
You are a github README assistant. Your task is to summarize a given README file,
indicating very briefly what the repo is about and installation instructions.
Here is the README:
{{exec "curl" "-LsSf" (concat "https://raw.githubusercontent.com/" (ask "Repo: ") "/refs/heads/" (ask "Branch: ") "/README.md")}}Cat Helper remote-capable
Takes a file path and renders its contents inside the prompt.
---
input:
schema:
path: string
---
You are a github README assistant. Your task is to summarize a given README file,
indicating very briefly what the repo is about and installation instructions.
Here is the README:
{{cat path}}INFO
When executed in a remote context, the file path is read from remote instead of local machine.
Tail Helper remote-capable
Render the last n lines from a given file.
---
input:
schema:
path: string
lines: integer
---
{{tail path lines=lines}}INFO
When executed in a remote context, the file path is read from remote instead of local machine.
Head Helper remote-capable
Render the first n lines from a given file.
---
input:
schema:
path: string
lines: integer
---
{{head path lines=lines}}INFO
When executed in a remote context, the file path is read from remote instead of local machine.
Env Helper remote-capable
Read environment variable
---
---
Shell Path: {{env "SHELL"}}
Shell Name: {{exec "basename" (env "SHELL")}}
Non-existent, with default: {{env "NON_EXISTENT" "Default Value"}}INFO
When executed in a remote context, the environment is read from remote instead of local.