guardrail-api-and-dashboard

Implements FastAPI guardrail middleware and Streamlit dashboard for prompt injection detection.

1|Updated Sep 1, 2026
One-click install
npx skills add https://github.com/nvtruongops/pi-guard --skill guardrail-api-and-dashboard-nvtruongops
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guardrail-api-and-dashboard
Source: https://github.com/nvtruongops/pi-guard/tree/main/.agents/skills/guardrail-api-and-dashboard
Command: npx skills add https://github.com/nvtruongops/pi-guard --skill guardrail-api-and-dashboard-nvtruongops

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires fastapi, pydantic, joblib, streamlit, pandas, requests, uvicorn.

What problem does it solve? Building a defensive layer in front of LLM applications requires wiring together a classifier, an API gateway, decision logic, and monitoring UI from scratch. This Skill provides the architecture and working code patterns for intercepting user prompts, scoring them with ML classifiers, enforcing ALLOW/BLOCK policies, and visualizing results before requests reach downstream LLMs. ## Core Features & Use Cases - FastAPI Guardrail Middleware: A /v1/chat/guardrail endpoint that loads a trained TF-IDF or DeBERTa classifier, computes a malicious probability score, and returns ALLOW or BLOCK decisions with latency metrics. - Streamlit Monitoring Dashboard: An interactive dashboard with live prompt testing, a tunable detection threshold slider, model benchmark tabs, and attack log views. - Docker Deployment: A Dockerfile pattern for packaging the API with uvicorn for containerized serving. - Use Case: A student or engineer building the PI-Guard capstone project can scaffold the guardrail API, connect it to Ollama or HuggingFace LLM targets, and demo live prompt injection blocking through the dashboard. ## Quick Start Ask the AI to scaffold the FastAPI guardrail endpoint and Streamlit dashboard for the PI-Guard project using a trained TF-IDF classifier with a 0.65 detection threshold.

Frequently Asked Questions about guardrail-api-and-dashboard

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a FastAPI middleware to detect prompt injection?

Load a trained classifier with joblib, define a POST endpoint accepting a Pydantic PromptRequest, and call predict_proba on the incoming prompt. Compare the malicious probability against a threshold and return a BLOCK decision with HTTP 403 semantics or forward the prompt to the target LLM.

How to create a Streamlit dashboard for LLM guardrail monitoring?

Use st.tabs to separate live prompt testing, model benchmarks, and attack logs. Add a sidebar slider for the detection threshold, send test prompts to the guardrail API with requests.post, and display ALLOW or BLOCK results with risk scores and latency.

Can the guardrail API forward prompts to Ollama or HuggingFace models?

Yes, the PromptRequest schema includes a model_target field such as ollama/llama3. After the classifier allows a prompt, the endpoint forwards it to the configured LLM target and returns the response in the llm_response field.

What threshold should I use for prompt injection detection?

The reference implementation uses a default threshold of 0.65 on the malicious probability score. The Streamlit dashboard exposes a slider from 0.0 to 1.0 so you can tune the trade-off between false positives and missed attacks interactively.

How do I deploy the FastAPI guardrail with Docker?

Use a python:3.11-slim base image, install dependencies from requirements.txt, copy the project, and expose ports 8000 and 8501. Run the API with uvicorn binding to 0.0.0.0 on port 8000.