Sarra
11/27/2025, 12:52 PMmichaelmichaelmichael
11/28/2025, 7:52 AMmax_input_tokens setting, you can easily achieve this by truncating your inputs based on character length (as a proxy for tokens) using transform functions. You can modify variables inline before they reach your prompt. This is great for truncating long text fields. See https://www.promptfoo.dev/docs/configuration/guide/#transforming-input-variables
yaml
defaultTest:
options:
transformVars: |
const MAX_CHARS = 4000; // Approx 1000 tokens
const truncate = (str) => str.length > MAX_CHARS ? str.slice(0, MAX_CHARS) + '...' : str;
// Apply to specific variables
if (vars.context) vars.context = truncate(vars.context);
return vars;
prompts:
- "Summarize: {{context}}"
You can also use nunjucks filters https://www.promptfoo.dev/docs/configuration/guide/#transforming-input-variables
Hope this helps!Sarra
11/28/2025, 2:29 PM