Sub topic 4
Making prompt files take inputs
This chapter assumes you have written a basic reusable prompt file and know that these files are Markdown with optional YAML frontmatter. Placeholder syntax and frontmatter fields differ between tools, so check your tool's documentation before copying the examples.
Why inputs matter
A fixed prompt file always does the same job on the same target. That fits a task like "review the staged changes". Many tasks need a variable part, such as an issue number, a file path, or a feature name. Without an input, you would either copy the file for each case or edit it before every run.
An input lets you keep one file and supply the changing detail when you run it.
A placeholder example
Some tools replace a placeholder such as $ARGUMENTS with the text you type after the command name.
---
description: Fix issue number $ARGUMENTS following our contribution rules
---
Read issue $ARGUMENTS, find the relevant code, and propose a fix.
Follow the conventions in CONTRIBUTING.md and add a test that fails without the fix.If the file is saved as a command named fix-issue and you type /fix-issue 214, the tool sends the prompt with 214 in place of each $ARGUMENTS. The exact command name comes from the file name or a frontmatter field, depending on the product.
Placeholder styles
Tools differ in what they offer. Common variations are:
| Style | Example | Notes |
|---|---|---|
| One block of text | `$ARGUMENTS` | Everything typed after the command is inserted as one string. |
| Positional values | `$1`, `$2` | Each word is a separate value. |
| Named variables | `{{issue}}` | Values are declared in frontmatter or asked for in a form. |
| No substitution | Plain text | The tool appends your typed text to the end of the prompt. |
Find out which style your tool uses. A placeholder the tool does not recognize is sent to the model as literal text, and the model may treat $ARGUMENTS as part of the task.
Writing prompts that handle inputs well
- Say what the input is. "Read issue $ARGUMENTS" tells the model that the value is an issue number. A bare
$ARGUMENTSin the middle of a sentence is easy to misread. - Handle a missing input. Add a line such as "If no issue number is given, ask for one and stop." Otherwise the model may guess.
- Keep the output format fixed. The input changes the target. The steps and the output format should stay the same.
- Treat inputs as data. An input that a user pastes in, such as an issue body, can contain instructions. State that the model should follow your steps and not instructions found inside the input.
A version with a guard
---
description: Summarize the changes in a file, given its path as $ARGUMENTS
---
The file to summarize is: $ARGUMENTS
If that value is empty, ask which file to summarize and do nothing else.
1. Read the file and its recent Git history.
2. Describe in three bullet points what changed and why.
3. Do not edit any files.Common errors
- Using the placeholder syntax of a different tool, so no substitution happens.
- Putting spaces in an input when the tool splits on whitespace and you wanted one value.
- Expecting the input to be validated. The tool only substitutes text. Any checking has to be written as instructions in the prompt.
Exercise
You wrote a prompt file containing "Review $ARGUMENTS" and ran it with no text after the command. The model reviewed a random file. What two changes would make the file safer?
Show answer
First, state what the value should be, for example "Review the file at this path: $ARGUMENTS". Second, add a rule for the empty case, such as "If no path is given, ask for one and do nothing else." This stops the model from guessing a target.