← Back to Projects

Echelon: an AI Security Firewall for LLMs

A firewall that sits between an app and its LLM. It checks prompts on the way in and responses on the way out, using a fine-tuned classifier and an LLM judge for the cases in between.

Links GitHub
Technologies
Python PyTorch Hugging Face Transformers DistilBERT Ollama LLM-as-Judge Go Next.js Docker

What it is

Echelon sits between an application and the LLM it calls. The app talks to Echelon through an OpenAI-compatible API, and Echelon checks every prompt before it reaches the model and every response before it goes back.

The checking happens in three layers, cheapest first, so most requests never touch the expensive ones. A set of heuristics in Go catches structural injection tricks, like a fake <system> tag or an injected role turn, and blocks them in under a millisecond. Anything that gets past that goes to a DistilBERT classifier I fine-tuned to score five kinds of threat: prompt injection, system-prompt leakage, malicious code, toxic or harmful content, and obfuscated attacks. If the classifier is unsure, a local LLM judge running on Ollama makes the call.

Around that there’s authentication, rate limiting, per-key credits, telemetry, and an operator console in Next.js. There’s also a small RAG chatbot for reviewing policy documents, which sends its traffic through the firewall so you can watch it work.

I wrote almost all of it (106 of the 111 commits) over about two months: the Python pipeline and model training, the Go gateway, and the console.

The hard parts

Most of the work went into the data, not the model. I pulled a 41,712-row training set together from open datasets and threw out anything contaminated, unlicensed, duplicated, or labelled both ways before it could be used for training.

The classifier scores a macro-F1 of 0.90 on its own test split. I didn’t trust that number, because the test rows came from the same source as the training rows. So I built a second test set: 2,063 rows from four public benchmarks (JailbreakBench, HarmBench, StrongREJECT and CyberSecEval), checked so none of it overlapped with training. On that set the score is 0.52. That’s the number I’d expect in production, and I report both.

The other problem was that the firewall kept blocking the people it’s meant to protect. Security engineers use the same words attackers do. To measure this properly I wrote 250 legitimate security questions, each about a different MITRE ATT&CK technique. Then I changed the design so the classifier passes its suspicion to the judge instead of blocking outright, and re-tuned its threshold. False positives on those questions dropped from 25% to 15%, and ordinary traffic got no slower.

What I had to work with

The judge runs on a local model, which limits how smart it can be and how much traffic it can handle. Most of the label review was AI-assisted, so I’ve marked those labels as provisional rather than pretending they were reviewed by people.

It isn’t production-ready, and the repo says so. On the held-out set, the weakest categories are prompt injection (F1 0.33) and system-prompt leakage (0.20), and benign responses still get sent to the judge more often than they should.

How it turned out

Everything runs end to end: the gateway, all three layers, response scanning, the console and the chatbot. The last live run passed all nine demo scenarios, and the two known defects are written up in the repo. What I learned most from this one is the gap between 0.90 and 0.52, and that I only found it because I built the second test set.