Work / Applied AI case study
PSYON-1: a small assistant, secured in public.
PSYON-1 is CyberPsyon's knowledge-grounded assistant: it answers questions about my work from the site's public content. It is also a working record of how I approach AI security, including the parts that are not finished.
- What it is
- Retrieval-augmented Q&A assistant. Not an agent: it takes no actions and calls no tools.
- Status
- Live · in active development
- Type
- Educational demonstration
- Built
- 2026, solo
How to read the evidence labels
- Implemented
- In the code. Not necessarily tested.
- Author-tested
- Tested by me, with the method described. Not independent.
- Documented
- Described in project docs; not re-verified for this page.
- Design intent
- What the design aims to do. Effect not yet measured.
- Proposed
- Planned, not built.
- Gap
- Known missing or incomplete.
The problem
Visitors often have one quick question: does he do workshops, what is CertRx, which certifications does he hold. A general-purpose chatbot can answer in that tone, and it will also invent a degree, a client or a credential if nothing stops it. On a professional site that is worse than no chatbot at all.
Public chatbots also attract people who try to break them. I wanted to build one where the security decisions are written down and tested, not assumed.
Objectives
- Answer only from approved public content, and say so when the answer is not there.
- Stay in scope: CyberPsyon and my work, not general help.
- Resist prompt extraction and instruction override well enough for a public demo.
- Keep cost per message bounded on a free-tier-friendly stack.
- Collect only what is needed to improve answers and study misuse, and delete it on a schedule.
Interaction design
PSYON-1 uses the site's terminal style, with suggestion chips for common topics so visitors do not face an empty prompt. Replies stream in as plain text, kept to roughly 40 to 80 words with one follow-up question pointing to a relevant page.
If the backend is unreachable, the interface falls back to short scripted answers and says it is offline, rather than failing silently. A notice before the first message explains what is logged and asks people not to share sensitive information. Implemented
It is deliberately not the only way to reach me. Every page has a direct contact route.
Knowledge grounding and retrieval
An ingestion script chunks the site's blog posts, lab guides and a public knowledge file, and the Worker embeds each chunk with the bge-base-en-v1.5 model (768 dimensions) into a Cloudflare Vectorize index.
At question time only the latest message is embedded. The top 5 matches are retrieved and any below a similarity score of 0.55 are discarded. The threshold came from a retrieval evaluation: every expected source stayed ranked first at thresholds from 0.40 to 0.60, and the weakest genuine match scored 0.619, so 0.55 leaves a margin without admitting weak matches. Author-tested
The knowledge base contains only content already published on this site. Confidential or unpublished material is never added, rather than added and hidden behind prompt instructions.
Architecture and trust boundaries
Four zones, from least to most trusted for my purposes: the visitor's browser, the Worker that holds the secrets and enforces the rules, Cloudflare services in the same account, and Anthropic as a third-party model provider.
Step 1 of 7: Visitor sends a message
The browser posts the new message plus recent conversation turns. Earlier PSYON-1 replies carry an HMAC tag the Worker issued when it wrote them.
Everything arriving here is treated as untrusted.
Read the full request path as text
- Visitor sends a message. The browser posts the new message plus recent conversation turns. Earlier PSYON-1 replies carry an HMAC tag the Worker issued when it wrote them. Everything arriving here is treated as untrusted.
- The gate checks the request. The Origin header must be cyberpsyon.com. Each IP gets 10 requests per minute. History is capped at 12 messages of 2,000 characters, and any assistant turn whose HMAC tag does not match is dropped. Stops casual cross-site use, bursts and forged assistant turns. Origin checks are not authentication: a non-browser client can set any Origin.
- The question is embedded. Only the latest user message is turned into a 768-dimension vector with the bge-base-en-v1.5 model on Workers AI. If this step fails, PSYON-1 answers from its base knowledge instead of erroring.
- Public content is retrieved. Vectorize returns the 5 closest chunks, and only chunks scoring 0.55 or higher are kept. The index holds the site's public blog posts, labs and a public knowledge file, nothing else. Confidential material is kept out of the index entirely rather than hidden by prompt instructions.
- Claude writes a grounded answer. Claude Haiku 4.5 receives the scope rules, the public knowledge file and the retrieved chunks, explicitly labelled as data and not instructions. Replies are capped at 400 tokens. Prompt rules reduce, but cannot eliminate, injection and invented answers.
- The turn is logged. After replying, the Worker stores the latest message, the reply and a keyed hash of the IP address in D1. Logging runs in the background and cannot block or break the reply. A daily job deletes rows older than 90 days. The IP hash is pseudonymous, not anonymous: anyone holding the key could test whether a known IP matches.
- The reply comes back. The reply is returned with a fresh HMAC tag. The browser strips any stray markdown and renders the text as plain text. Rendering as text, never HTML, keeps model output from injecting markup into the page.
Security controls
Each control does one specific job. None of them, alone or together, makes the system secure in an absolute sense; the table says what each one does and does not do.
| Control | Status | What it does | What it does not do |
|---|---|---|---|
| Origin allowlist | Implemented | Rejects chat requests whose browser Origin is not cyberpsyon.com, which stops other websites from using the chatbot from their pages. | Authenticate anyone. A script outside a browser can send any Origin header. |
| Per-IP rate limit | Author-tested | Allows 10 requests per minute per IP address. Observed returning 429 responses during red-team bursts. | Stop a distributed attacker, or cap total monthly spend. |
| Input bounds | Implemented | Keeps only the last 12 messages and cuts each to 2,000 characters, which bounds prompt size and cost. | Judge whether the content is malicious. |
| HMAC-tagged assistant turns | Implemented | Each reply carries a signature from a server-side key. Assistant turns sent back without a valid signature are dropped, so a visitor cannot forge what PSYON-1 'said' earlier. | Protect against injection in the visitor's own messages. |
| Scope and anti-injection rules | Author-tested | The system prompt limits answers to CyberPsyon and Ben, forbids revealing instructions and tells the model to ignore attempts to change its rules. | Guarantee compliance. Prompt rules are a mitigation, not a boundary. |
| Retrieved text marked as data | Implemented | Retrieved chunks are wrapped with an instruction to treat them as data, not instructions. | Fully prevent indirect injection if hostile text ever entered the index. The index holds only my own public pages. |
| Public-only knowledge | Implemented | The index is built from published blog posts, labs and a public knowledge file. Nothing private is in it to leak. | Prevent the model from misstating public facts. |
| Secrets kept server-side | Implemented | API keys, the signing key and admin tokens live in Cloudflare secrets, never in the repository or the browser. | Protect against a compromised Cloudflare account. |
| Gated admin and debug routes | Implemented | Content ingestion needs a secret token. The retrieval debug view needs an allowed Origin and a separate token, and otherwise behaves like a normal request. | Replace rotating tokens when people or devices change. |
| Plain-text rendering | Implemented | The page renders replies as text, never HTML, and strips stray markdown. | Stop a misleading answer. It stops injected markup. |
| Output length cap | Implemented | Replies are capped at 400 tokens, which limits cost per message. | Provide a spend ceiling. There is no monthly budget guard yet. |
| Daily health check | Implemented | A scheduled GitHub Actions job sends one question each day and fails, emailing me, if the reply is an error or empty. Catches a rejected API key, exhausted credits or an outage within a day. | Check answer quality or security. One request a day cannot detect brief outages. |
| Bot challenge (e.g. Turnstile) | Gap | Not implemented. | Automated clients are only slowed by the rate limit. |
| Spend ceiling and alerting | Gap | Not implemented. | Cost control relies on the rate limit and output cap. |
Adversarial testing and evaluation
16 of 16 attack prompts refused or kept on topic, in both runs
Author-run script against my own live Worker. Categories: system prompt extraction (direct, translation, encoding, hypothetical and continuation variants), instruction override and persona switching, role confusion and fake system messages, knowledge base dumping, and out-of-scope requests (poems, code, maths, news, other people). The November rerun followed a prompt update and an API key rotation. Requests are now spaced 6.5 seconds apart so the rate limiter does not cut the run short, and a leak means the reply contains verbatim text from the real prompt or knowledge file.
Does not show: Single-turn prompts only and author-run. The first November attempt exposed a flaw in the test itself: it flagged a refusal that merely mentioned 'system prompt' as a leak, so the check was rewritten. It does not cover multi-turn attacks, paraphrased leaks or behavior after future prompt or model changes.
10 of 10 queries retrieved the expected source first
Author-written queries, each with a known correct source page, run through a token-gated debug route that returns raw retrieval scores. Swept thresholds from 0.40 to 0.60.
Does not show: Ten queries is a small sample and they were written by the system's author. It measures retrieval, not whether the final answer is accurate or well grounded.
Not yet measured
Answer accuracy, unsupported-answer frequency, response latency and cost per conversation have not been measured, so no figures are given. Gap The planned protocol: a fixed question set with reference answers scored against the source pages, a multi-turn and indirect-injection suite run against a staging Worker rather than the live one, and per-request latency and token counts recorded for one week.
Data handling and privacy
| Data | Where it goes | How long it is kept |
|---|---|---|
| Your message and recent turns | PSYON-1 Worker (Cloudflare), then Anthropic's API to generate the reply | Not kept by the Worker beyond the request, except the latest message in the log below |
| Latest message | Workers AI, to build a search vector | Not stored by PSYON-1 |
| Log row: time, latest message, reply, context-found flag | Cloudflare D1 | Up to 90 days, deleted by a daily scheduled job |
| IP address | Rate limiter, and a keyed HMAC-SHA256 hash in the log row | Raw IP not stored; the hash is kept with the row for up to 90 days |
| Errors and request metadata | Cloudflare Workers observability logs | Under Cloudflare's log retention settings |
Logging stores the visitor's latest message, which can contain anything a visitor types. That is a real privacy cost, accepted for now because reading real questions and attacks is how the system improves. Options I am weighing: logging only flagged security events, shortening retention, or truncating messages. Visitors are told what is stored before they send anything, and the full details are on the privacy page.
Limitations
- Prompt-based scope rules can be bypassed by attacks the red-team did not try.
- The model can still misstate public facts. There is no automated grounding check on each answer, and sources are not shown to the visitor.
- The IP hash is pseudonymous, not anonymous, and logged messages may contain whatever visitors type.
- No bot challenge and no spend ceiling: an automated client could run up cost within the rate limit.
- The knowledge file must be updated by hand when the site changes, and can fall out of date.
- Testing is author-run. Nothing here has been independently assessed.
- Failures can be quiet. In 2026 a rejected API key went unnoticed for weeks because the interface fell back to scripted answers instead of showing an error. The daily health check was added in November 2026 so that cannot happen silently again.
What comes next
- Show the source page behind each answer. Proposed
- Add a bot challenge and a monthly spend ceiling with alerting. Proposed
- Move to security-event logging with shorter retention. Proposed
- Run the grounding, multi-turn and indirect-injection suites on a staging Worker and publish the method and results. Proposed
Stack
- Cloudflare Workers
- Workers AI (bge-base-en-v1.5)
- Vectorize
- Claude Haiku 4.5 (Anthropic API)
- Cloudflare D1
- Workers rate limiting
- Web Crypto HMAC-SHA256
- React (Docusaurus)