https://promptfoo.dev/ logo
Number of Input Tokens
# ❓|questions
s
Hello, Does anyone know whether it's possible or not to limit the number of input tokens. If so please let me know how can it be done exactly? Thank you for your help!
m
Hello @Sarra, there isn't a direct
max_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
Copy code
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!
s
Thank you very much @michaelmichaelmichael for your help I will have a look on that!