Skip to content
OPQAI.
Sourced intermediate / 💻 Coding Free tools

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

  1. 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.
  2. Create a configuration file: Create a file named promptfooconfig.yaml in a new folder. This file tells Promptfoo what to test and how.
    redteam:
      plugins:
        - harmful
        - pii
        - prompt-extraction
      strategies:
        - jailbreak
        - prompt-injection
      targets:
        - id: my-agent
          config:
            url: "http://localhost:3000/agent"
    Note: The url in the targets section 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.
  3. Run the tests: Open your terminal or command prompt, navigate to the folder where you saved promptfooconfig.yaml, and run the following command:
    promptfoo eval --config promptfooconfig.yaml
    You should see Promptfoo start running various tests against your agent, reporting which attacks were successful or blocked.

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/agent with 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.

Keep going

More Coding workflows