CoolFace
Apppublic

RaghuAiEng/enterprise-guardrailed-rag

sourceHugging Faceupdated 27d agoView on Hugging Face
0likes
App README

Enterprise Guardrailed Multi-Department RAG System

![Python 3.11+](https://www.python.org/downloads/) ![Streamlit](https://streamlit.io/) ![ChromaDB](https://www.trychroma.com/) ![Tests](tests/)

An enterprise-grade, guardrailed Retrieval-Augmented Generation (RAG) system with strict Role-Based Access Control (RBAC) across multi-departmental document repositories (Engineering, Finance, Public), black-box Chipotle-style security guardrails, and an interactive Ragas Evaluation Dashboard.


Key Architecture & Features

mermaid
flowchart TD
    User([User in Streamlit UI]) --> Guardrail[Black-Box Security Gate]
    
    subgraph Security Gating
        Guardrail -->|Regex Filter| PII[PII Sanitization SSN/Card]
        Guardrail -->|Pattern Guard| Inj[Prompt Injection Defense]
        Guardrail -->|Fast Classifier| Scope[Corporate Scope Classifier]
    end
    
    Scope -->|Out-of-Scope / Attack| Refuse([Polite Canned Refusal])
    Scope -->|In-Scope Query| VectorSearch[ChromaDB Vector Store]
    
    subgraph Dynamic RBAC
        VectorSearch -->|where: department_access in role| FilteredChunks[Authorized Chunks Only]
    end
    
    FilteredChunks --> Generator[Grounded LLM Synthesis]
    Generator -->|Context Empty/Lacks Evidence| FallbackRefuse([Standard Refusal Fallback])
    Generator -->|Grounded Answer| Citations([Answer with Source & Page Citations])
  1. 1.Document Ingestion & Chunking:
  2. 2.Parsed with Docling and PyPDF into 600-token chunks with 120-token sliding overlap.
  3. 3.Strictly enforces mandatory chunk metadata: department_access, source_file, and page_number (Constitution Principle III).
  4. 4.Dynamic RBAC Retrieval:
  5. 5.Pre-filters vector search at the ChromaDB index level by active user role:
  6. 6.Public → ['Public']
  7. 7.Finance-Manager → ['Finance', 'Public']
  8. 8.Engineering-Lead → ['Engineering', 'Public']
  9. 9.Admin → ['Engineering', 'Finance', 'Public']
  10. 10.Guarantees 0% cross-department unauthorized data leakage (SC-001).
  11. 11.Black-Box Guardrails & Scope Enforcement:
  12. 12.Redacts sensitive PII (SSN, credit cards).
  13. 13.Intercepts prompt injection attacks.
  14. 14.Classifies out-of-scope queries (general coding, trivia, casual advice) and returns polite canned refusal without expensive LLM generation or hallucination.
  15. 15.Strict Groundedness:
  16. 16.All responses cite source files and exact page numbers ([Doc: <file>, Page: <page>]).
  17. 17.Returns standardized fallback ("I do not have sufficient information in the authorized corporate documents to answer this question.") when context is ungrounded.
  18. 18.Interactive UI & Ragas Dashboard (Streamlit + Plotly):
  19. 19.Tab 1: Conversational chat with citation cards and collapsible chunk previews.
  20. 20.Tab 2: Visual evaluation analytics rendering Plotly bar charts of Ragas metrics (Faithfulness, Answer Relevance, Context Recall).

Quickstart

1. Installation

bash
# Clone and enter directory
cd my-adv-rag

# Create virtualenv and install dependencies
uv venv .venv
source .venv/bin/activate
uv pip install -r requirements.txt

2. Configure Environment

bash
cp .env.example .env
# Add your GEMINI_API_KEY or OPENAI_API_KEY (optional for local mock execution)

3. Run Automated Test Suite

bash
pytest tests/ -v

4. Run Offline Benchmark Suite

bash
python -m src.eval.benchmark_runner --dataset data/eval/golden_dataset.json --output data/eval/eval_results.json

5. Launch Streamlit Application

bash
streamlit run app.py

Project Structure

text
.
├── app.py                    # Streamlit Multi-Tab Dashboard
├── data/
│   ├── engineering/          # Engineering documents
│   ├── finance/              # Confidential finance documents
│   ├── public/               # Public documents
│   ├── eval/                 # Golden datasets & benchmark results
│   └── chroma_db/            # Local ChromaDB persistent store
├── src/
│   ├── config/settings.py    # Pydantic Settings
│   ├── models/               # Domain, security, query & eval schemas
│   ├── ingestion/            # Docling parser, chunker, & pipeline
│   ├── retrieval/            # ChromaDB RBAC vector store & retriever
│   ├── security/             # PII sanitizer, injection guard, guardrails
│   ├── generation/           # Grounded prompts & LLM generator
│   ├── engine/               # RAG orchestrator pipeline
│   └── eval/                 # Ragas metrics & CLI benchmark runner
└── tests/                    # 16 unit, RBAC, and integration tests