Guide: Guard API
Complete guide to the high-throughput /v1/guard firewall endpoint. Inspect inputs, mask credit cards and PII, and neutralize prompt injections.
Endpoint Overview
POST /v1/guard is the core real-time firewall endpoint in EngineNear. It executes in sub-5ms on standard gateway nodes, analyzing prompt text against active tenant policy rules.
The endpoint supports both input-mode inspection (before prompt reaches the model) and output-mode verification (validating model completions against canary tokens and unmasked sensitive data).
Request Parameters
The request accepts a JSON object conforming to guardRequestSchema:
- prompt (string, required): Up to 65,536 characters (64 KB chunk budget per Rule 3).
- maskSecrets (boolean, default: true): When enabled, detected sensitive spans are replaced with tokenized placeholders.
- regionPacks (array, optional): Select from ["US", "IN", "EU"] to enable localized PII rules (e.g. Aadhaar, Verhoeff, SSN, IBAN).
- destinationHost (string, optional): Target provider hostname (e.g. api.openai.com) for telemetry and egress auditing.
- neutralize (boolean, default: false): Strips injection markers and system instruction overrides from text.
Code Examples (curl, TypeScript, Python)
The examples below demonstrate sending a prompt containing sensitive credit card data with maskSecrets enabled:
curl -s -X POST http://localhost:3000/v1/guard \
-H "Content-Type: application/json" \
-H "Authorization: Bearer test-token" \
-d '{
"prompt": "Process subscription on card 4532 0151 1283 0366 now",
"maskSecrets": true
}'Response & Findings Breakdown
The gateway returns an HTTP 200 JSON object with verdict status and granular finding coordinates:
- action: allow, warn, mask, or block based on compiled tenant policy priority.
- allowed: boolean indicating whether prompt execution should proceed.
- promptHash: SHA-256 hash uniquely indexing this prompt for immutable audit trails.
- findings: Array of detected spans with start/end indices, confidence score, category, and ruleId.
- tokenizedPrompt: The sanitized prompt with sensitive data masked if policy prescribes mask.