Skip to content
< all work

Agents & MCP · Personal project · 2026

A grounded assistant for my portfolio

A retrieval-grounded assistant that answers questions about my work from my portfolio's own pages, with layered input and output guardrails, per-IP rate limits and a daily token budget that pauses it.

ragguardrailsllm-security

Answers come only from retrieved site content, injection attempts get a refusal that is logged with its reason, and spend has a hard daily ceiling.

Role
Sole engineer
Stack
Django · PostgreSQL · pgvector · gemini-embedding-001 · gemini-2.5-flash-lite · Server-sent events · Next.js

The assistant only knows what my portfolio says. It is built and tested but not deployed yet. An ingest command reads the sitemap, splits each page into 1,500-character chunks with a 200-character overlap, and hashes every chunk so unchanged text is never embedded twice. Embeddings come from gemini-embedding-001. Its native width is 3,072, so I request 768 dimensions through Matryoshka output dimensionality, which keeps the pgvector HNSW index under its 2,000-dimension limit. Retrieval takes the 4 nearest chunks by cosine distance, and an admin switch can pull any chunk out of reach.

Input checks run cheapest first. A length limit (2,000 characters) comes before a regex filter for common injection phrasings, then PII redaction that rewrites emails, phone and card numbers and tells the user it did so. Last comes a classifier call on gemini-2.5-flash-lite that labels the message on-topic, off-topic, harmful or injection. The regex filter is a coarse spam filter, not a security boundary, and the classifier fails open during an outage. Grounding carries the real weight: the system prompt treats retrieved text as reference data, never as instructions. The answer streams over server-sent events, and the accumulated output is checked as it streams, so a leaked-prompt phrase split across chunks still stops the stream.

Abuse controls are deliberately boring. Each client IP gets 15 messages a minute and 200 a day. A daily budget of 3,000,000 tokens and an environment flag both act as a kill switch that returns 503. The Google SDK runs in its own sidecar container on the internal network, because its dependencies clashed with the main Django image. Ten Django tests run against a deterministic fake model and cover streaming, injection refusal, the PII notice, the kill switch and the curation flag.