quadkit-ai-guard
AI input/output guard pipeline for the Quadkit Framework — LLM safety and content filtering
Overview
Content safety and guardrails for the Quadkit Framework. Runs an ordered pipeline of input and output guards against every LLM call — blocking prompt injections, redacting PII, enforcing length limits, restricting topics, and optionally using an LLM classifier for advanced jailbreak detection. Zero-config usage starts with sensible defaults.
Install
uv add quadkit-ai-guard
Quick Start
from quadkit import Application
from quadkit.di.module import Module, module
from quadkit.ai.guard import GuardModule
from quadkit.ai.guard.config import GuardConfig
@module(
imports=[
GuardModule.configure(
GuardConfig(
injection_detection=True,
pii_detection=True,
pii_action="redact",
max_input_chars=8000,
)
)
]
)
class AppModule(Module):
pass
async with Application.boot(modules=[AppModule]) as app:
# use app.container to resolve services
...
Configuration
Zero-config usage: Call
GuardModule.configure()with no arguments to use defaults.
Option 1 — YAML file
# application.yaml
ai_guard:
injection_detection: true
pii_detection: true
pii_action: "redact"
max_input_chars: 8000
restricted_topics: []
Option 2 — Profiles + Environment Variables (recommended)
export QK_AI_GUARD__PII_ACTION=redact
# Environment variables for each field
Option 3 — Python
from quadkit.ai.guard.config import GuardConfig
from quadkit.ai.guard import GuardModule
config = GuardConfig(
injection_detection=True,
pii_action="redact",
max_input_chars=8000,
restricted_topics=["violence", "adult_content"],
)
GuardModule.configure(config)
Config reference
| Field | Default | Env var | Description |
|---|---|---|---|
enabled |
True |
QK_AI_GUARD__ENABLED |
Master on/off switch |
injection_detection |
True |
QK_AI_GUARD__INJECTION_DETECTION |
Enable heuristic prompt injection detector |
injection_action |
"block" |
QK_AI_GUARD__INJECTION_ACTION |
Action on injection: "block" or "warn" |
pii_detection |
True |
QK_AI_GUARD__PII_DETECTION |
Enable PII detection on user inputs |
pii_action |
"redact" |
QK_AI_GUARD__PII_ACTION |
Action on PII: "redact", "block", or "warn" |
pii_entities |
[] |
QK_AI_GUARD__PII_ENTITIES |
PII entity types to scan |
pii_redaction_output |
True |
QK_AI_GUARD__PII_REDACTION_OUTPUT |
Apply PII redaction to LLM outputs |
max_input_chars |
0 |
QK_AI_GUARD__MAX_INPUT_CHARS |
Maximum input character count |
max_output_chars |
0 |
QK_AI_GUARD__MAX_OUTPUT_CHARS |
Maximum output character count |
length_action |
"block" |
QK_AI_GUARD__LENGTH_ACTION |
Action when a length limit is exceeded |
restricted_topics |
[] |
QK_AI_GUARD__RESTRICTED_TOPICS |
Topic keywords to block |
enable_llm_guards |
False |
QK_AI_GUARD__ENABLE_LLM_GUARDS |
Use LLM for advanced injection/jailbreak detection |
guard_model |
"gpt-4o-mini" |
QK_AI_GUARD__GUARD_MODEL |
Model used for LLM-based guards |
llm_guard_threshold |
0.7 |
QK_AI_GUARD__LLM_GUARD_THRESHOLD |
Confidence threshold for LLM guard action |
sensitivity_level |
"medium" |
QK_AI_GUARD__SENSITIVITY_LEVEL |
Guard aggressiveness: "low", "medium", "high" |
Module Factory Methods
| Method | Description |
|---|---|
GuardModule.configure(config) |
Configure with explicit config |
GuardModule.stub(config) |
Minimal config for testing |
Key Features
- Input guards: PromptInjectionDetector, PIIDetector, TopicRestrictor, InputLengthGuard
- Output guards: PIIRedactor, OutputLengthGuard
- LLM-based guards: Optional LLMInjectionDetector and LLMJailbreakDetector
- Guard results:
AggregateGuardResultwith passed, blocked, redacted, warned states @guardeddecorator: Function-level guard attachment- Lifecycle hooks: GuardInputCheckedHook, GuardOutputCheckedHook, GuardPipelineCompletedHook
Testing
async with Application.boot(
modules=[
GuardModule.stub(
GuardConfig(
injection_detection=True,
injection_action="block",
)
)
]
) as app:
# your test code
...
Key Source Files
| File | What it contains |
|---|---|
src/quadkit/ai/guard/module.py |
GuardModule.configure(), .stub() |
src/quadkit/ai/guard/config.py |
GuardConfig |
src/quadkit/ai/guard/pipeline/guard_pipeline.py |
GuardPipeline orchestrator |
src/quadkit/ai/guard/pipeline/result.py |
GuardCheckResult, AggregateGuardResult, GuardAction |
src/quadkit/ai/guard/input/injection.py |
PromptInjectionDetector heuristics |
src/quadkit/ai/guard/input/pii.py |
PIIDetector regex patterns |
src/quadkit/ai/guard/output/pii_redactor.py |
PIIRedactor |
src/quadkit/ai/guard/di/provider.py |
GuardProvider boot and registration |
Metadata
Release files for quadkit-ai-guard 0.0.50
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 | Actions |
|---|---|---|---|---|
| quadkit_ai_guard-0.0.50.tar.gz | 57.8 kB | Without provenance | Details for quadkit_ai_guard-0.0.50.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| quadkit_ai_guard-0.0.50-py3-none-any.whl | Python 3 | none | any | Details for quadkit_ai_guard-0.0.50-py3-none-any.whl |
Total release size: 109.8 kB
Release files / quadkit_ai_guard-0.0.50.tar.gz
| Download URL | quadkit_ai_guard-0.0.50.tar.gz |
|---|---|
| Size | 57.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
640a5debb3e1348ad4072446d18bc0873c64105ac2cd4286514dcfcf10740eb5
|
|
BLAKE2b-256 checksum How to use checksums |
0256d7de78c7ff00b6da040910f9d4571222979a2e42bec098388db6f8173861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / quadkit_ai_guard-0.0.50-py3-none-any.whl
| Download URL | quadkit_ai_guard-0.0.50-py3-none-any.whl |
|---|---|
| Size | 52.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b89fcfa0d7587ec85994576c55275f3d23ff624094fa7527a442770daeeafe5
|
|
BLAKE2b-256 checksum How to use checksums |
48427ab7b362dcc45f6da9fec4ee2de161c4f42a243dfbb9a6d32354446b57e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for quadkit-ai-guard 0.0.50
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.