What is Anar Guard?
Anar Guard is the governance and compliance layer of the Anar platform. It sits between your applications and AI models, enforcing policies, detecting PII, scanning for unsafe content, and maintaining a complete audit trail of every AI interaction.
Guard is purpose-built for GCC government deployments where regulatory compliance, data sovereignty, and content safety are non-negotiable. It integrates with every other Anar product and can operate as a standalone governance service.
Core Capabilities
Policy Engine
Define rules that govern what content is allowed, warned, logged, or blocked. Policies support keyword matching (including Arabic with morphological variants) and regex patterns with configurable action escalation.
PII Detection
GCC-optimized detection of personally identifiable information including UAE Emirates IDs, Saudi national IDs, GCC phone numbers, IBAN numbers, credit cards with Luhn validation, and Arabic context-aware extraction.
Safety Scanning
LLM-powered content classification using Llama Guard 4 via Groq. Scans both user inputs and model outputs across 14 safety categories, from violent crimes to code interpreter abuse.
Content Filtering
Bilingual toxicity detection and restricted topic filtering with Arabic morphological variant matching. Covers 15 English and 24 Arabic toxic keywords plus 28 restricted topics across both languages.
Compliance Reports
Automated compliance assessment against 5 regulatory frameworks: UAE AI Ethics, SDAIA (Saudi), Qatar AI Charter, Oman AI & Digital, and EU AI Act. Reports include weighted scoring, evidence, gap analysis, and remediation recommendations.
Batch Policy Operations
Create, update, and delete policies in bulk for efficient governance configuration. Batch operations validate all entries before committing, with detailed per-item error reporting.
CSV Audit Export
Export the full audit trail as CSV for offline analysis, compliance reporting, and integration with external SIEM systems.
Safety Metrics Dashboard
Real-time safety metrics aggregation showing scan volumes, block rates, PII detection rates, and policy violation trends over configurable time windows.
Audit Trail
Every evaluation, safety check, PII detection, and proxy request is logged with timestamps, user attribution, severity levels, and full result data. Queryable by event type, severity, and user.
Architecture
Guard is a FastAPI service backed by PostgreSQL. It integrates with Groq for Llama Guard safety scanning and optionally routes LLM calls through Gateway.
Guarded Proxy
Guard can operate as a transparent proxy for LLM calls. The /proxy/chat/completions endpoint accepts OpenAI-compatible requests and wraps them with full input/output scanning:
- Detect PII in the user message
- Run safety classification on the input
- Block if unsafe, otherwise forward to Gateway
- Scan the model response for safety violations
- Log everything to the audit trail
- Return the response with safety metadata attached
Default Policies
Guard seeds four default governance policies on startup:
| Policy | Type | Action | Description |
|---|---|---|---|
| No Medical Advice | keyword | block | Blocks medical diagnosis/prescription keywords in English and Arabic |
| No Political Content | keyword | block | Blocks political discussion keywords |
| No Personal Data in Responses | regex | warn | Warns on GCC phone, email, and Emirates ID patterns |
| Toxicity Filter | keyword | block | Blocks violent/harmful language in English and Arabic |
Alerts and Webhooks
Guard includes an alert rules engine that monitors metrics like policy violations, PII detections, safety blocks, and critical events. When thresholds are breached, alerts fire and can dispatch webhook notifications with HMAC-SHA256 signatures.
Getting Started
Guard runs on port 8002 (backend) and 3002 (dashboard). Configure your GROQ_API_KEY to enable Llama Guard safety scanning, or Guard will skip LLM-based checks and rely on policy/PII/content filtering alone.
Environment Variables
| Variable | Description | Default |
|---|---|---|
DATABASE_URL | PostgreSQL connection string | postgresql+asyncpg://... |
JWT_SECRET | JWT signing secret | Must be changed in production |
GROQ_API_KEY | Groq API key for Llama Guard | None (safety checks skipped if unset) |
GROQ_GUARD_MODEL | Safety model identifier | meta-llama/llama-guard-4-12b |
GATEWAY_BASE_URL | Gateway URL for proxy mode | http://localhost:8080/v1 |
Observability
Guard is instrumented with OpenTelemetry via anar_shared.setup_otel(). When OTEL_EXPORTER_OTLP_ENDPOINT is set, traces, logs, and metrics are exported to the OTel Collector. Without it, instrumentation is a no-op.
MCP Server
Guard exposes a Model Context Protocol server at /mcp via FastApiMCP, enabling AI assistants and development tools to interact with policies, PII detection, safety scanning, and compliance reports programmatically.
Test Suite
460 tests across 34 endpoints cover policies, batch policy operations, PII detection, safety scanning, content filtering, compliance reports, audit trail, CSV export, webhooks, alerts, safety metrics, and telemetry ingestion.
cd guard/backend && uv run pytest
Next Steps
- Policy Engine -- Define keyword and regex rules for content governance
- PII Detection -- Understand the GCC-optimized PII detection pipeline
- Safety Scanning -- Configure Llama Guard content classification
- Compliance Reports -- Generate framework-aligned compliance assessments
- API Reference -- Full endpoint documentation