https://promptfoo.dev/ logo
How to add dynamic prompt with multiple placeholde...
# ❓|questions
c
My prompt looks like {"role":"system", "content": < {company}, {company_description}, ... , {previous_context},} then again repeated at user level with a few placeholders How can I use this reliably inside promptfooconfig with variables separately from another file such that the prompt gets build up completely and then we can test against user_input, currently the prompt part allows prompt with placeholders but no support for passing placeholders variables values, and input csv only allows a single column input ??
m
Hey! You can absolutely do this with promptfoo. The CSV format supports as many columns as you need, and each column becomes a variable that gets substituted into your prompt. Here's how to set this up for your use case: ## Solution: Multiple Placeholders in CSV Your prompt (prompt.json):
Copy code
json
[
  {
    "role": "system",
    "content": "You are a helpful assistant for {{company}}. Description: {{company_description}}. Context: {{previous_context}}"
  },
  {
    "role": "user",
    "content": "{{user_input}}. Additional context: {{user_context}}"
  }
]
Your test data (tests.csv):
Copy code
csv
company,company_description,previous_context,user_input,user_context,__expected
"Acme Corp","Leading widget provider","Customer called yesterday","What's my order status?","Premium customer",contains: order
"TechStart Inc","Software solutions","No previous interactions","How do I reset my password?","Free tier",contains: password
Your config (promptfooconfig.yaml):
Copy code
yaml
prompts:
  - file://prompt.json

providers:
  - openai:gpt-5-nano

tests: file://tests.csv
That's it! All 5 placeholders (company, company_description, previous_context, user_input, user_context) get filled from the CSV columns. Each row in the CSV becomes a separate test case. You can also separate static and dynamic variables. If some variables like
company
,
company_description
, and
previous_context
stay the same across all your tests, you can define them once in your config and only put the changing values in your CSV: Config:
Copy code
yaml
prompts:
  - file://prompt.json

providers:
  - openai:gpt-5-nano

defaultTest:
  vars:
    company: "Acme Corp"
    company_description: "Leading widget provider"
    previous_context: "Customer has been with us for 5 years"

tests: file://tests.csv
Simplified CSV (tests.csv):
Copy code
csv
user_input,user_context,__expected
"What's my order status?","Premium customer",contains: order
"How do I reset my password?","Free tier user",contains: password
The variables in
defaultTest.vars
automatically get merged with each row from your CSV. This keeps your test data cleaner and easier to maintain. For more details and examples: - Test cases & CSV format: https://promptfoo.dev/docs/configuration/test-cases - Prompts & variables: https://promptfoo.dev/docs/configuration/prompts All of these approaches work today! Best of luck!
2 Views