secure-genai-gateway: Secure GenAI Gateway: The Firewall for Prompts, Outputs, and AI Spend

A centralized Python gateway that scrubs sensitive input, blocks risky responses, encrypts audit trails, and gives enterprises one place to govern every LLM request.

7 to 9 min read • View on GitHub • More from vishalranjan1265-ui

A fortified checkpoint stands between a cluster of application services and a distant model core. One request pouch is being inspected at the gate while a blocked path is sealed shut, showing that LLM access is controlled at the perimeter rather than treated like a direct pipe.
The repo’s core idea is architectural, not cosmetic: put policy at the edge so prompts, outputs, and audit records all pass through one controlled gate.
Key Takeaways

Most teams still bolt safety onto LLM features one app at a time. That works until privacy, compliance, and cost land on different owners and nobody can explain who approved what. This repo takes a harder position: if enterprise AI is going to be real infrastructure, it needs a perimeter.

The AI firewall enterprises keep reinventing

The project’s strongest idea is the GenAI DMZ. Put one gateway between business apps and model providers, then force every request through the same policy chokepoint. That shifts governance out of scattered microservices and into a single control plane.

In the repo’s own framing, the gateway is designed to sit between production applications and LLM providers such as AWS Bedrock, OpenAI, and Claude. That matters because the dangerous part of GenAI is not only the model call. It is everything that can leak into it, and everything that can leak back out.

The interesting part is not the boxes. It is the short-circuit behavior. Policy can stop a request before the model is called, and it can still stop a response after the model replies.

One request, four gates

The orchestration engine in src/gateway.py runs a strict sequence: ingress analysis, upstream dispatch, egress analysis, then hardening. If the prompt trips a security rule, the request is blocked before the provider call. If the response looks unsafe, it is stopped before the user sees it.

That is the real product move. The gateway does not just proxy traffic. It decides whether traffic should exist at all, and it leaves an encrypted trail behind either way.

A close-up conveyor of four inspection stations processes a single request. One lane is diverted into a blocked bin before the provider step, while the main lane passes through redaction, model dispatch, response checking, and locked audit storage.
The pipeline is physical on purpose here. You can see where the request is scrubbed, where it is stopped, and where the audit record is sealed.

The filters are simple on purpose

The security filters lean on precompiled regex patterns in config rather than model-based detection. That is a conscious tradeoff. Regex is fast, predictable, and easy to reason about in a gateway whose job is to make hard calls quickly.

ConcernAd hoc app integrationSecure GenAI Gateway
PII scrubbingHandled differently in each serviceCentralized before provider calls
Prompt injection checksOften inconsistent or missingApplied at ingress in one place
Output inspectionUsually skippedChecked before the response returns
Audit loggingApp-specific and unevenEncrypted centrally
Provider switchingRequires code changes across appsConcentrated in the gateway layer
Policy ownershipSpread across teamsOwned as a shared control plane
Offline developmentUsually depends on live APIsCan emulate locally without credentials

This is not trying to be clever AI security. It is trying to be boring in the best way: cheap to run, easy to audit, and hard to bypass.

The gateway assumes the model is untrusted

Most products stop at prompt filtering. This repo also treats the model response as an attack surface. That matters because leakage can happen in both directions: sensitive input on the way in, and restricted or revealing output on the way out.

The egress check makes the gateway feel more like a security boundary than an SDK. If the model tries to echo secrets, policies can still catch it before exposure.

Why offline emulation is the underrated feature

One of the most practical details in src/llm_client.py is offline emulation mode. If AWS credentials are missing, the gateway can keep running locally or in CI instead of breaking the workflow or burning provider credits.

That makes the project friendlier to development, testing, and policy iteration. It also reveals the product instinct behind the code: this is meant to be an operational layer, not a demo wrapper around a model endpoint.

The repo also includes encrypted audit logging with Fernet-backed protection, IAM-based runtime credential resolution, and a Docker setup with a non-root user. Those are small signals, but together they point to a project that is thinking like infrastructure, not like a prototype.

What this replaces, and what it does not

Compared with app-level integrations, a centralized gateway reduces duplicated policy logic and makes governance visible. Compared with a traditional API gateway, it is opinionated about AI-specific risks like prompt injection, output leakage, and auditability.

It is not trying to be a full agent platform. It is trying to be the control layer in front of one. That narrow scope is why the repo works as an argument: enterprises do not just need model access. They need a perimeter around it.

ArchitectureBest atWeakness
App-level LLM callsFast feature shippingPolicy drift across services
Traditional API gatewayRouting and throttlingNo AI-specific safety checks
Secure GenAI GatewayIngress and egress governanceMay be more than small teams need