Aegis-RAG — Security-First Query Pipeline

Aegis-RAG — Security-First Query Pipeline A sequence diagram generated by Archify. POST /api/v1/query evaluate(query) CLEAN similarity_search top-k chunks generate(context, query) answer sanitize(answer) clean 200 JSON {answer, sources} Security screen (LLM01) Retrieve + generate Sanitize + respond (LLM05) Client · web console / API · Sequence participant Client web console / API Aegis-RAG API · FastAPI middleware · Sequence participant Aegis-RAG API FastAPI middleware SecurityGateway · LLM01 · pre-retrieval · Sequence participant SecurityGateway LLM01 · pre-retrieval ChromaDB · vector store · Sequence participant ChromaDB vector store Ollama · llama3.2 · Sequence participant Ollama llama3.2 OutputSanitizer · LLM05 guard · Sequence participant OutputSanitizer LLM05 guard Legend request return security default message

Security-first ingress

  • • API key (constant-time) + per-key rate limit run in middleware before the route
  • • SecurityGateway screens every query before retrieval (LLM01)
  • • A BLOCKED verdict short-circuits to HTTP 400 — no retrieval, no LLM call

Grounded RAG

  • • Retrieval and generation run only on a CLEAN verdict
  • • Answer grounded in top-k chunks from ChromaDB
  • • System prompt treats retrieved docs as untrusted data (indirect-injection guard)

Output guard

  • • OutputSanitizer checks every response (LLM05)
  • • A reflection leak fails loud as HTTP 500 — never a silent leak
  • • Each stage is wrapped in an OpenTelemetry span