aegis-llm
A pluggable, multi-layer LLM jailbreak defense pipeline for Python. Drop it into any codebase — framework-agnostic, provider-agnostic, zero mandatory dependencies.
Install
pip install aegis-llm
Or from source:
git clone https://github.com/your-org/aegis-llm
cd aegis-llm
pip install -e .
Quickstart
from aegis import Decision, Request, SplitPipeline
from aegis.layers import (
AuditLogger, InputValidation, OutputFilter,
RateLimiter, ToolAccess,
)
pipeline = SplitPipeline(
pre=[
InputValidation(),
ToolAccess(role_tool_map={
"admin": ["query", "create", "delete"],
"viewer": ["query"],
}),
RateLimiter(max_requests=20, window_seconds=60),
],
post=[
OutputFilter(),
AuditLogger(sink=print),
],
)
request = Request(user_id="u1", message="Show tasks", user_role="viewer")
# Phase 1 — before your LLM call
pre = pipeline.run_pre(request)
if pre.decision == Decision.BLOCK:
raise Exception(pre.layer_results[-1].block_reason)
# Your LLM call — any provider
allowed_tools = pre.context.get("available_tools", [])
llm_response = your_llm(request.message, tools=allowed_tools)
# Phase 2 — after your LLM call
post = pipeline.run_post(request, llm_response, pre)
final = post.context.get("filtered_response", llm_response)
How it works
Every request flows through a Pipeline — an ordered list of Layers. The pipeline short-circuits on the first BLOCK, so nothing downstream runs on a rejected request.
Request → Layer 1 → Layer 2 → ... → PipelineResult
↓
BLOCK → return immediately
SplitPipeline splits this at the LLM boundary: pre-phase layers run before your model call, post-phase layers run after. Your code owns the LLM invocation; aegis owns the gating on either side.
Built-in layers
| Layer | Phase | What it does |
|---|---|---|
InputValidation |
pre | Regex/keyword blocklist — blocks naive injection attempts |
SemanticRouter |
pre | Intent classifier gate — plug in any classifier callable |
ToolAccess |
pre | RBAC — filters the tool schema to what the user's role permits |
RateLimiter |
pre | Sliding-window quota per user — pluggable backend (Redis, etc.) |
OutputFilter |
post | Scans LLM response for internal disclosure, redacts or blocks |
AuditLogger |
post | Structured audit record — plug in any sink (CloudWatch, Datadog, etc.) |
Writing a custom layer
Subclass Layer and implement one method:
from aegis import Layer
from aegis.models import Decision, LayerResult
class TenantIsolation(Layer):
def process(self, request, context):
if request.metadata.get("tenant_id") != context.get("expected_tenant"):
return LayerResult(
decision=Decision.BLOCK,
layer_name=self.name,
block_reason="tenant_mismatch",
)
return LayerResult(decision=Decision.PASS, layer_name=self.name)
Drop it anywhere in the pipeline:
from aegis import Pipeline
from aegis.layers import InputValidation, ToolAccess
Pipeline([InputValidation(), TenantIsolation(), ToolAccess(...)])
SemanticRouter — bring your own classifier
from aegis.layers import SemanticRouter
def my_classifier(message: str) -> tuple[str, float]:
# call sklearn, HuggingFace, an LLM, anything
return "task_query", 0.92
SemanticRouter(
classifier=my_classifier,
allowed_intents=["task_query", "task_create"],
confidence_threshold=0.75,
)
RateLimiter — pluggable backend
The default backend is in-memory. For multi-process deployments, implement RateLimitBackend:
from aegis.layers.rate_limiter import RateLimitBackend, RateLimiter
class RedisBackend(RateLimitBackend):
def get_timestamps(self, user_id): ...
def record_request(self, user_id, timestamp): ...
def evict_before(self, user_id, cutoff): ...
RateLimiter(max_requests=10, window_seconds=60, backend=RedisBackend())
AuditLogger — pluggable sink
from aegis.layers import AuditLogger
# CloudWatch, Datadog, S3, database — anything callable
AuditLogger(sink=lambda record: my_logger.info(record))
Running tests
pip install -e ".[dev]"
pytest
Metadata
Release files for aegis-llm 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aegis_llm-0.1.3.tar.gz | 15.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aegis_llm-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.1 kB
Release files / aegis_llm-0.1.3.tar.gz
| Download URL | aegis_llm-0.1.3.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcff68254b556e25829744e963b4206c2d348816cea610ab3addacbabb514ff3
|
|
BLAKE2b-256 checksum How to use checksums |
0adc780b8d0c32721b631bbe6f065820d56d7ea8cd69f5be5e07a5b3fb98d7bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency logRelease files / aegis_llm-0.1.3-py3-none-any.whl
| Download URL | aegis_llm-0.1.3-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d49aefb161a59f005f68c9641370ccd646d3440b0c43edc399d92c847b315736
|
|
BLAKE2b-256 checksum How to use checksums |
db5dc81c74afbb1b749fc916b1a0bde6fc6665853eb2611cf028d8196c09488f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency logSecurity for aegis-llm 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for aegis_llm-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.