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:
String Concatenation
Concatenate any number of strings together using the concat helper.
Exec Helper
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}}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")}}