AI Prompt Plugin
Overview
The AI Prompt Guard plugin helps monitor and filter AI-generated or user-submitted content for compliance or security purposes.
- Detects and blocks harmful or prohibited prompts.
- Integrates AI models to analyze and validate input data.
Lab Environment
This lab tests a Kong API Gateway deployment using a FastAPI endpoint. To simplify, both the containerized Kong API Gateway and the FastAPI endpoint are installed locally on a Windows 10 machine. A Docker Compose file is used to deploy Kong, along with other applications like Prometheus, Zipkin, the ELK Stack, and more.
Make sure that you have installed Docker Desktop.
Simply installing Docker in WSL2 without Docker Desktop may introduce some issue when configuring the communication between the containerized Kong API Gateway and the FastAPI application that is installed on the local host.
Pre-requisites
- Postman
- Setup the Kong API Gateway
- Setup the FastAPI Endpoint
- Kong Manager OSS Access
- Create the Routes and Services
- Enable the Basic Authentication Plugin
Enable AI Prompt Guard Plugin
To enable the plugin, go to Kong Manager > Plugins > New Plugin > Traffic Control > Select AI Prompt Guard. As an example, we can allow any prompts related to Python while blocking prompts pertaining to Java. To do this, specify them in the Allow and Deny Patterns:
Field | Value |
---|---|
Allow Pattern | .*Python.* |
Deny Patterns | .*Java.* |
You can disable all other plugins for now.
Test the plugin via Postman
To setup Postman, please see Testing with Postman
Open Postman and create a new request. Rename it to FastAPI via Kong - AI Prompt Guard. Enter the URL below:
http://localhost:8000/kong/healthy
In the Body tab, select raw and add the prompt:
{
"messages": [
{
"role": "user",
"content": "How do you run a Python script?"
}
]
}
Click Send. Note that it doesn't return any answer to the question/prompt, it will just return "healthy".
If we change the prompt to ask about Java, we'll get Bad Request
error.