Sub topic 4
Making prompt files take inputs
This chapter assumes you can already write a reusable prompt file with a fixed task, as covered in the previous chapter. It also assumes you know basic Markdown and YAML frontmatter, and that you have run a slash command or similar shortcut in an AI coding assistant. Placeholder syntax differs between tools, so the examples show the common patterns. Check your tool's documentation for exact names.
Why a prompt file needs inputs
A fixed prompt file works for tasks that never change, such as "review my staged changes". Many tasks have one varying part: an issue number, a file path, a feature name, or a target audience. Without inputs you have two poor options. You can copy the file for each variation, which clutters the repository. Or you can type the variable part into the chat after running the command, which breaks the idea of a packaged prompt.
An input is a value you supply when you invoke the prompt file. The tool inserts it into the prompt text before the model sees anything. The model never sees the placeholder, only the finished text.
The simplest form: one argument string
Many tools offer a placeholder such as $ARGUMENTS that stands for everything typed after the command name. This prompt file comes from the plan for this tutorial:
---
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 you save it as fix-issue.md and run the command with /fix-issue 142, the model receives "Read issue 142, find the relevant code, and propose a fix." The same file serves every issue.
Some points to notice:
- The placeholder can appear more than once. Each occurrence is replaced with the same text.
- The placeholder can appear in the frontmatter
description, which some tools show in the command picker. Not every tool substitutes there, so test it. - The value is plain text. The tool does not check that
142is a number or that the issue exists.
Positional arguments
When the prompt needs more than one value, a single string becomes awkward. Some tools split the input on whitespace and expose the pieces as $1, $2, and so on.
---
description: Translate a document into another language
---
Translate the file $1 into $2.
Keep headings, code blocks, and links unchanged.
Write the result next to the original, with the language code added to the file name.Running the command with docs/intro.md French gives $1 the value docs/intro.md and $2 the value French.
Positional arguments are short but fragile. The order is invisible to anyone reading the invocation, and a value that contains a space splits into two arguments unless the tool supports quoting. For more than two values, consider a different design, described below.
Simulating substitution to understand it
Substitution is plain text replacement. The following script imitates what a tool does, which helps you reason about edge cases. It is not any product's real implementation.
import re
import shlex
def expand(template: str, raw_args: str) -> str:
"""Replace $ARGUMENTS and $1, $2, ... in a prompt template."""
parts = shlex.split(raw_args)
text = template.replace("$ARGUMENTS", raw_args)
def positional(match: re.Match) -> str:
index = int(match.group(1))
return parts[index - 1] if index <= len(parts) else ""
return re.sub(r"\$(\d+)", positional, text)
template = "Translate the file $1 into $2."
print(expand(template, "docs/intro.md French"))
print(expand(template, "docs/intro.md"))
print(expand(template, '"my notes.md" French'))The output is:
Translate the file docs/intro.md into French.
Translate the file docs/intro.md into .
Translate the file my notes.md into French.The second line shows a common failure. A missing argument becomes an empty string, and the prompt still reads like a sentence. The model then has to guess what went in the gap. Some tools behave differently, for example by leaving the placeholder in the text or by reporting an error, so test what yours does.
Named inputs
Some tools let you declare named inputs, and the editor prompts you for each value. In VS Code prompt files, for example, a variable written as ${input:topic} asks for a value, and a form such as ${input:topic:the subject to explain} adds hint text. Other tools offer an argument-hint frontmatter field that shows the expected shape of the input in the command picker, such as [issue-number] [priority].
---
description: Draft release notes for a version
argument-hint: [version] [audience]
---
Draft release notes for version $1, written for $2.
Use the merged pull requests since the previous tag as the source.Named inputs are easier to read and harder to get in the wrong order. They depend on a specific product's syntax, though, so a file that works in one tool may leave a literal ${input:topic} in the prompt in another. This is the main portability cost of inputs.
How the pieces fit together
The diagram shows what happens between typing the command and the model producing an answer.
Substitution happens in the tool, not in the model. This is why a placeholder the tool does not recognize reaches the model as literal text such as $ARGUMENTS.
Designing the prompt around the input
A placeholder is only a hole in the text. The surrounding prompt must still make sense for every value someone might supply. These habits help.
- Name what the value is. Write "Read issue $ARGUMENTS" instead of "Read $ARGUMENTS". The first stays understandable if the value is
142or#142. - Say what to do when the input is missing. Add a line such as "If no issue number was given, ask for one and stop." This turns the empty-string failure into a question.
- Say what to do when the input is wrong. For example: "If the issue cannot be found, report that and do not guess."
- Keep the input small. Pass identifiers, paths, and short phrases. For long material, pass a path and tell the model to read it.
- Keep the output format fixed. Inputs change the task's subject, not its shape. A fixed format makes results comparable across runs.
Here is the earlier issue prompt after applying these habits:
---
description: Fix an issue by number
argument-hint: [issue-number]
---
The issue number is: $ARGUMENTS
If the line above has no number after the colon, ask me for the issue number and stop.
Otherwise, read that issue and find the relevant code. If the issue does not exist, say so and stop.
Follow the conventions in CONTRIBUTING.md and add a test that fails without the fix.
Reply with the files you plan to change and a short reason for each, before editing anything.Putting the input on its own labeled line makes an empty value easy for the model to notice.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The model receives a literal `$ARGUMENTS` | The tool uses a different placeholder syntax | Check the documentation for the exact name |
| A sentence has a gap such as "into ." | A positional argument was missing and became empty | Add a rule for missing input, and show an argument hint |
| `$2` holds half of a file name | The value contained a space and was split | Quote the value if the tool supports it, or use one string argument |
| `$1` and `$2` are swapped in practice | The order is not visible when invoking | Switch to named inputs or document the order in the hint |
| The placeholder works in the body but not in the description | Substitution may not apply to frontmatter | Test it, and keep the description free of placeholders if unsure |
Inputs are text from outside
Whatever the user types is inserted straight into the prompt. If the value comes from somewhere you do not control, such as an issue title copied from a public tracker, it can contain instructions aimed at the model. Treat inputs as data. Prefer passing identifiers and letting the agent read the source itself, and keep tools restricted where untrusted text is involved. The security chapter returns to this.
Exercise
A teammate's prompt file says "Summarize the changes in $1 for $2." Someone runs it with only one argument, release-2.4. Describe what the model may receive, and name two edits to the prompt file that make this failure safer.
Show answer
In a tool that replaces missing positional arguments with empty text, the model receives "Summarize the changes in release-2.4 for ." and has to guess the audience. Two edits: add an instruction such as "If the audience is missing, ask me for it and stop", and add an argument-hint such as [version] [audience] so the expected inputs are visible when the command is run. Putting each input on its own labeled line also helps the model notice an empty value.
Exercise
Why does a prompt file that uses ${input:topic} risk breaking when you move it to another tool, and what would you check first?
Show answer
Substitution is done by the tool, and placeholder syntax is product-specific. A tool that does not recognize ${input:topic} leaves it as literal text in the prompt. First check the other tool's documentation for its placeholder and argument syntax, then run the prompt once with a sample value and inspect the text the model actually receives.