Why do you need Promptfoo right now?
You’ve just finished writing a “pro” prompt that runs smoothly on GPT-4. However, when switching to Claude 3.5 or Gemini, the results suddenly drift off-key. Even worse, just changing a few words in your old prompt can cause previously correct cases to suddenly fail.
Instead of manually copying and pasting every question into ChatGPT for visual comparison—a subjective “vibe-check”—you need a more professional workflow. In reality, manually evaluating 50 test cases can consume 2 hours of your time. With Promptfoo, this figure drops to under 5 minutes.
Promptfoo is a CLI tool that helps you run batch tests across multiple models simultaneously. It allows for side-by-side result comparisons and automatic scoring based on custom criteria. Think of it as an essential Unit Test suite for AI engineers.
Quick Start: Try Promptfoo in 5 minutes
As long as your computer has Node.js, you’re ready. You don’t need to be a coding expert because this tool primarily works with intuitive YAML configuration files.
Step 1: Installation
Open your terminal and install Promptfoo globally using the following command:
npm install -g promptfoo
Step 2: Project Initialization
Create a new directory and run the initialization command:
promptfoo init
This command creates a promptfooconfig.yaml file containing sample configurations for you to experiment with immediately.
Step 3: Run Evaluation
After setting up your API Key (e.g., export OPENAI_API_KEY=sk-xxx), run:
promptfoo eval
Step 4: Visualize Results
To avoid looking at dry text in the terminal, type:
promptfoo view
A dashboard interface will appear. Here, you can see a detailed comparison table between prompt versions and different models.
Decoding Promptfoo’s Core Structure
To optimize your workflow, you need to master the three main components in the configuration file:
1. Prompts
You can declare multiple prompt variants to find the “perfect match.” For example:
prompts:
- "Write a short ad for {{product_name}}"
- "You are a professional copywriter, write an engaging caption for {{product_name}}"
2. Providers (AI Models)
Promptfoo supports a wide range of providers from OpenAI and Anthropic to local models running via Ollama. Testing simultaneously on gpt-4o and claude-3-5-sonnet will help you clearly see differences in writing style and reasoning across models.
3. Tests (Test Scenarios)
This is where you define your “assignments” and expected outputs (assertions). This method is extremely effective for catching edge cases.
tests:
- vars:
product_name: "Mini coffee maker"
assert:
- type: contains
value: "12-month warranty"
- type: javascript
value: output.length < 150
Advanced: Scoring with LLM-as-a-judge
Checking for keywords (contains) is sometimes not enough. How do you know if a response is friendly enough? This is where we use a powerful model (like GPT-4o) as a “judge” to score the model being tested.
Use the llm-rubric type in the assert section:
- type: llm-rubric
value: "The response must not mention competitor names and must include appropriate emojis."
provider: openai:gpt-4o
This method helps quantify abstract criteria. You will have a clear score from 0 to 1 instead of guessing the quality.
Real-world Experience Deploying Promptfoo
To avoid wasting resources and time, you should keep a few points in mind:
- Cost Control: Don’t rush to run 100 test cases on GPT-4 immediately. Use
gpt-4o-minior Ollama to filter out basic logic errors before moving to expensive models. - API Key Security: Never hard-code keys. Create a
.envfile; Promptfoo will automatically detect and secure this information. - Full Automation: Integrate Promptfoo into your CI/CD pipeline (like GitHub Actions). If a new prompt drops the Pass rate below 90%, the system will block the code merge.
- Leverage Caching: Promptfoo caches old results by default. If you don’t change the input, it won’t call the API again, significantly saving on your end-of-month bill.
Prompt optimization is no longer a matter of “vibes” when you have data in hand. This tool turns experimentation into a scientific process with concrete evidence. Good luck building stable AI systems!

