← All case studies
Dojo Wizard — Building a guarded, read-only RAG assistant for SecDojo
AI case study

Dojo Wizard: a guarded, read-only RAG assistant that answers “where is that feature?” inside SecDojo

SecDojo's users kept asking community admins on Discord where features lived and how to use them. I designed and shipped an in-app assistant that answers from the platform's own content, with citations, role-aware retrieval and five layers of guardrails.

RoleLead AI Engineer
TimelineNov 2025 – Jan 2026
Team5 engineers
ProductSecDojo · CyberLab · CyberLearn
Python FastAPI Gemini OpenAI Qdrant RabbitMQ Celery Laravel TypeScript Docker

TL;DR

01 · Context & goal

Too many features, not enough answers

SecDojo is a cybersecurity training platform serving both individual learners (B2C) and organisations (B2B). It bundles several products: hands-on labs (CyberLab), courses and learning paths (CyberLearn), teams, entities, wallets and certifications, each with its own modules and sub-features.

As the platform grew, users increasingly turned to the community Discord to ask the same questions: where is feature X? how do I create a team? where do I download my VPN profile? Every answer depended on an admin being online.

Before

Support lived outside the product.

User is stuck→Discord→waits for an admin→gets a link

After

Answers live where the question happens.

User is stuck→Dojo Wizard→cited, streamed answer

The goal

Ship an in-app assistant that answers questions about the platform's content and features, not its technical internals, and is safe enough to put in front of every user:

02 · The product

Dojo Wizard, inside every SecDojo page

A side panel opens from any page; a full-page mode keeps the chat history. Quick actions cover the most frequent questions (creating entities and teams, adding members, wallet and transactions), and users can attach a document to their question.

Side panel, menu and full-page mode, in light and dark themes. Click to enlarge.
03 · Architecture

One AI service, hidden behind the platform

The browser never talks to the AI service. The existing Laravel backend authenticates the user, injects their identity and roles, and relays the streamed answer. The AI service owns the models, retrieval, guardrails and chat history.

embed + upsert UserB2C · B2B FrontendTypeScript · panel + page Laravel gatewayauth · identity + rolesSSE relay AI service assistant + RAG tool guardrails chat history · feedback Geminichat · function calling OpenAIembeddings · alt. chat Qdrantvector index · filters MySQLsessions · messages Content eventslabs · courses · help Ingestion workersRabbitMQ · Celery
Request path (top) and ingestion path (bottom). Each product's backend relays to the same AI service.

Why this architecture

Gateway in front of the AI

Reused the platform's existing authentication; the AI service is never exposed publicly.

Identity and roles are set server-side, so neither the client nor the model can choose them.

RAG as a tool, not a pre-step

Gemini decides when to call the search tool, so small talk and follow-ups don't trigger useless retrieval.

Filters and limits are still applied by the server, not by the model.

Qdrant for retrieval

Self-hostable in our Docker stack, fast payload filters for roles and status, and aliases for zero-downtime re-indexing.

Small embedding model

text-embedding-3-small (1536 dims): low cost, strong quality for short, structured platform content.

Streaming with SSE

Token-by-token answers over plain HTTP, easy to relay through the PHP backend and its proxies.

Async ingestion

Content changes are indexed by Celery workers on separate queues, so indexing never slows down chat.

04 · How retrieval works

Index what users read, retrieve only what they may see

The index covers lab descriptions, write-ups, course content and help-center articles: the content users actually navigate. Technical internals are excluded on purpose.

Ingestion: incremental and idempotent

Content eventlab, course or article created, updated or deleted
Sanitisehidden text, scripts and injected instructions removed or quarantined
Chunkby headings, 512 tokens, 64 overlap
Diffcontent hash: unchanged chunks skipped
Embedbatches of 100, retry with backoff
Upsertdeterministic IDs, role + status in payload

Full rebuilds go to a fresh collection and swap an alias atomically, so users never see a half-built index.

Query time: a narrowing funnel

All chunks role, status & language filters
20 candidates cosine similarity
Score ≥ 0.14 off-topic questions stop here
MMR diversity λ = 0.7
Top 5 passages ≤ 3,000 tokens, cited [S1]…

Stage widths are illustrative. If the vector store is unavailable, a keyword fallback answers with the same visibility rules.

05 · Security & guardrails

The model is untrusted. So are the user and the documents.

A cybersecurity audience will try to break an assistant. That's the culture. I treated every input as hostile: the user's message, the indexed documents and the model's own output. Defense in depth meant that when one layer only flagged an attack, the next one still held.

1

Input guard

Normalised every message (Unicode folding, invisible characters removed, letter-spaced text collapsed) and scored injection signals in English and French: instruction overrides, system-prompt extraction, persona and “developer mode” switches, role-tag spoofing, tool escalation, secret requests, exfiltration links. High scores were blocked with a friendly redirect; medium scores ran in a hardened mode without optional tools.

2

Document guard (indirect injection)

At ingestion, stripped what a reader never sees but a model would: HTML comments, scripts, hidden and bidi characters, remote images, non-allowlisted links. Then it quarantined any chunk carrying AI-directed instructions. Because the corpus is about hacking, attack vocabulary (“dump credentials”, “privilege escalation”) was explicitly not treated as an injection.

3

Context isolation

Retrieved passages were wrapped as data with explicit grounding rules; any attempt inside a passage to close that block or impersonate a system or tool message was neutralised before reaching the model.

4

Tool gateway

One choke point between the model and the backend: an allowlist of read-only tools (write tools refused at registration), schema-checked arguments, unknown arguments dropped, a budget of 3 tool calls per turn, and every call audited. Identity and roles were injected from the authenticated session: a model asking for roles: ["admin"] simply had that argument removed.

5

Output guard

A random canary embedded in the system prompt detected prompt leaks; API keys, tokens and private keys were redacted; external images and non-allowlisted links (classic exfiltration channels) were stripped; citations pointing to passages that weren't provided were removed.

Red-team results by attack type (input guard)

43 attack prompts across 8 categories (EN + FR). Every attempt was caught; “flagged” ones ran in hardened mode, where layers 4–5 still held.
BlockedFlagged (hardened mode)
View as table
CategoryAttemptsBlockedFlaggedMissed
0
injection attempts caught
0
benign questions blocked (false positives)
0
poisoned documents neutralised at ingestion
0
leaks caught by the output guard
0
write-ups returned to learners, even with forged roles

The first red-team run caught 42/43 attacks: a letter-spaced “i g n o r e …” prompt slipped through and one benign question about mobile jailbreaks was flagged. Adding compact-form matching and domain-aware rules brought it to 43/43 with zero false positives.

06 · My role & actions

What I owned

Lead AI engineer on the AI service (44 of the repository's 76 commits), working with four other engineers.

Chat service

SSE chat endpoint, Gemini and OpenAI providers behind one streaming protocol, file attachments, chat history and feedback, data model and migrations.

RAG pipeline

Ingestion, chunking, embeddings, Qdrant schema and filters, retrieval funnel, the function-calling search tool, evaluation and calibration.

Guardrails

Threat model, the five guard layers, red-team datasets and the regression tests that keep them honest.

Platform integration

A standalone Laravel gateway to prove the end-to-end flow, then integration into the product backends: SSE relay, identity and roles, sessions and files.

Key decisions

07 · Results & impact

Measured, not assumed

Retrieval quality and guardrails were measured offline on curated sets: a 12-question validation set spanning labs, write-ups and help articles, 3 off-topic probes, and the red-team set above.

0
hit@5: the right source in the top 5
0
recall@5
0
MRR: the right source ranked first
0
off-topic questions answered “not found”
0
automated tests, all green
0
re-embeddings when content is unchanged

Choosing the similarity threshold

Too low lets off-topic questions through; too high loses the right answer. 0.14 was the only setting that maximised both.
Hit@5Off-topic rejected
View as table
ThresholdHit@5Recall@5MRROff-topic rejected
0.10100%0.961.002/3
0.14100%0.961.003/3
0.1583%0.790.833/3
0.2558%0.580.583/3

Impact