Test AI Agents for Security Flaws with Promptfoo
Job to be done: Test AI agents for security vulnerabilities.
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Student
Test your JAMB prep chatbot for security flaws before sharing it with friends.
- 9-5 employee
Verify your company's internal AI assistant won't leak sensitive data before deployment.
What you’ll get
You will learn how to use Promptfoo to test your AI agents for security vulnerabilities. This approach works by simulating attacks on your agent to see if it can be tricked into performing unintended actions, like sending sensitive data.
Tools you need
- Promptfoo (free): A tool for testing and evaluating AI prompts and agents.
Steps
- Install Promptfoo: Follow the installation instructions for your operating system from the official Promptfoo website. This usually involves downloading an executable or using a package manager.
- Create a configuration file: Create a file named
promptfooconfig.yamlin a new folder. This file tells Promptfoo what to test and how.
Note: Theredteam: plugins: - harmful - pii - prompt-extraction strategies: - jailbreak - prompt-injection targets: - id: my-agent config: url: "http://localhost:3000/agent"urlin thetargetssection should be replaced with the actual address where your AI agent is running. The author does not specify the exact URL, so you will need to provide this based on your setup. - Run the tests: Open your terminal or command prompt, navigate to the folder where you saved
promptfooconfig.yaml, and run the following command:
You should see Promptfoo start running various tests against your agent, reporting which attacks were successful or blocked.promptfoo eval --config promptfooconfig.yaml
Original source
This workflow is based on an article by rudratosh posted on DEV Community. The author explored tools for testing AI agent security, focusing on identifying gaps where agents might lie about blocking attacks.
Notes & variations
- Common mistake: Forgetting to replace
http://localhost:3000/agentwith the correct URL for your AI agent. If the URL is wrong, Promptfoo won’t be able to connect and test your agent. - Tip for better results: Explore the different plugins and strategies available in Promptfoo (like
harmful,pii,jailbreak,prompt-injection) to cover a wider range of potential security issues. - Alternative: For simpler prompt testing without security focus, you can often use the chat interfaces of AI models directly. However, for dedicated security testing, Promptfoo is specifically designed for this purpose.