Prompts and vars: one prompt, many questions
Vars are the values a prompt template leaves blank: one prompt with a {{question}} hole runs once per test, each test filling the hole with its own value.
Last updated: 15 Oct, 2026 · Promptfoo 0.124.1
The A Python provider: your own app under test lesson ran two questions through one prompt. That is the shape of almost every suite: a single prompt template and a table of inputs. This lesson writes the template once and lets a list of tests drive many questions through it, then shows what happens when a var name does not line up.
A template with one hole
A prompt is a string with {{name}} placeholders. Here the template wraps each question in a sentence, and {{question}} is the hole every test fills.
prompts:
- "A customer asks: {{question}}"A test per question
Each entry under tests carries a vars block naming the value for this run and an assert for the answer. The template does not change; only the var does.
- vars:
question: Where is order A17?
assert:
- type: contains
value: 3 March
Running three questions through one prompt
Three tests, one template. Promptfoo renders the prompt once per test, calls the provider, and checks each answer.
providers:
- file://support_bot.py
prompts:
- "A customer asks: {{question}}"
tests:
- vars:
question: Where is order A17?
assert:
- type: contains
value: 3 March
- vars:
question: How long does a refund take?
assert:
- type: contains
value: five working days
- vars:
question: Where is order B99?
assert:
- type: contains
value: could not find
View the code here
# the shop support bot: find the answer in the handbook, or say it is missing
HANDBOOK = {
"a17": "Order A17 shipped on 3 March by courier.",
"refund": "Refunds take five working days.",
}
def call_api(prompt, options, context):
asked = prompt.lower() # the rendered prompt is the question
for key, line in HANDBOOK.items():
if key in asked:
return {"output": line}
return {"output": "I could not find that in the handbook."}
promptfoo eval --no-tableStarting evaluation eval-2KH-2026-10-14T19:17:01 Running 3 test cases (up to 4 at a time)... Creating cache folder at ~/.promptfoo/cache. ✓ Eval complete (ID: eval-2KH-2026-10-14T19:17:01) » View results: promptfoo view » Share with your team: https://promptfoo.app » Feedback: https://promptfoo.dev/feedback Results: ✓ 3 passed (100%) 0 failed (0%) 0 errors (0%) Duration: 0s (concurrency: 4)
A misspelled var renders an empty hole
The var name in a test must match the name in the template. If it does not, promptfoo does not error: it fills the hole with nothing and runs on. Here the test spells the var questoin, so {{question}} has no value and renders empty. The box table would still show the template {{question}} in its header, so the hole is invisible there. Writing the run to a file and reading results.results[].prompt.raw shows the prompt that ran.
providers:
- file://support_bot.py
prompts:
- "A customer asks: {{question}}"
tests:
- vars:
questoin: Where is order A17?
promptfoo eval -o out.json >/dev/null 2>&1
# read back the prompt that ran, and the reply
python3 - <<'PY'
import json
r = json.load(open("out.json"))["results"]["results"][0]
print("vars :", r["vars"])
print("prompt.raw :", repr(r["prompt"]["raw"]))
print("output :", repr(r["response"]["output"]))
PYvars : {'questoin': 'Where is order A17?'}
prompt.raw : 'A customer asks: '
output : 'I could not find that in the handbook.'What the hole shows
- The prompt rendered to
'A customer asks: ', with nothing where the question should be. The misspelled var was never used. - No error was raised. A missing or misspelled var is a silent empty string, not a failure, so a typo can pass unnoticed.
- The bot answered its fallback, because an empty question matches no handbook word. The hole changed the answer without any warning.
Where vars earn their keep
- A table of questions run through one prompt, so adding a case is adding a row.
- Several vars in one template, such as a question and a customer name filled together.
- Sharing a prompt across suites, where only the vars differ from one file to the next.
{{name}} in the template has a matching var, and read prompt.raw from the JSON output rather than trusting the table header, which shows the template.Related
- Previous: A Python provider: your own app under test
- Next: Tests in a CSV file
- Reference: Promptfoo prompts and vars docs
- Fix the typo back to
questionand confirm the prompt fills and the answer returns. - Add a second var, such as a customer name, to the template and to one test.
- Read
results.results[].prompt.rawfor a correct test and compare it with the template in the table header.
You understood something today that you didn't yesterday.