How ara-5/ai-security-gateway works
AI Security Gateway screens user input and model output, produces an allow/flag/sanitize/block verdict, and records an audit event. Its central runtime path is request entry → direction-specific detectors → risk scoring and decision → audit. The README also documents model backends, labeled-corpus evaluation, multi-model comparison, and baseline replay. Some evaluation modules were not sampled; their documented relationships are shown with README evidence rather than implying source inspection.
Main entry points: pipeline.py Security gateway · cli.py CLI commands · multi_model.py Multi-model comparison · engine.py Attack replay and diff
Components 20
Request entry
- CLI commands
cli.py - HTTP API
gateway/api.py
Security inspection
- Request and verdict types
gateway/schemas.py - Security gateway
gateway/pipeline.py - Security detectors
gateway/detectors - Detector foundation
gateway/detectors/base.py - Risk scoring and decisions
gateway/scoring.py - Gateway thresholds
gateway/config.py - Audit logger
gateway/audit.py - Daily JSONL audit logs
logs
Model backends
- Backend registry
models/registry.py - Offline mock models
models/mock_backend.py - Model backend interface
models/base.py - OpenAI and Anthropic
models
Evaluation and replay
- Attack and holdout corpora
data - Detection benchmark
benchmark/evaluate.py - Multi-model comparison
benchmark/multi_model.py - Attack replay and diff
replay/engine.py - Replay baseline
data/replay_baseline.json
Other components
- User or agent
Connections 27
- User or agent → CLI commands: runs command
cli.py - User or agent → HTTP API: sends request
README.md - CLI commands → Security gateway: inspects text
cli.py - HTTP API → Security gateway: routes inspection
gateway/api.py - HTTP API → Backend registry: selects backend
gateway/api.py - Security gateway → Security detectors: runs detectors
gateway/pipeline.py - Security detectors → Detector foundation: uses foundation
gateway/detectors/prompt_injection.py - Security detectors → Request and verdict types: reads request
gateway/detectors/prompt_injection.py - Security gateway → Risk scoring and decisions: aggregates results
gateway/pipeline.py - Risk scoring and decisions → Gateway thresholds: uses thresholds
gateway/scoring.py - Security gateway → Gateway thresholds: limits input
gateway/pipeline.py - Security gateway → Audit logger: records verdict
gateway/pipeline.py - Audit logger → Daily JSONL audit logs: appends events
gateway/audit.py - Audit logger → Request and verdict types: reads request fields
gateway/audit.py - Backend registry → Offline mock models: registers mocks
models/registry.py - Backend registry → OpenAI and Anthropic: loads when keyed
models/registry.py - Offline mock models → Model backend interface: implements
models/mock_backend.py - CLI commands → Detection benchmark: runs benchmark
cli.py - Detection benchmark → Attack and holdout corpora: evaluates cases
README.md - CLI commands → Multi-model comparison: runs comparison
cli.py - Multi-model comparison → Backend registry: uses backends
README.md - Multi-model comparison → Security gateway: compares protection
README.md - Multi-model comparison → Attack and holdout corpora: tests attacks
README.md - CLI commands → Attack replay and diff: runs replay
cli.py - Attack replay and diff → Security gateway: inspects cases
replay/engine.py - Attack replay and diff → Attack and holdout corpora: loads corpus
replay/engine.py - Attack replay and diff → Replay baseline: diffs outcomes
README.md