@caelaralabs/agent-guard
v1.2.0
Published
Guard agent inputs and outputs: prompt-injection scanning, input firewall, output validation, PII redaction and domain trust checks. Typed SDK (ESM and CommonJS) and CLI.
Maintainers
Readme
@caelaralabs/agent-guard
Checks for the text going into and out of your agents: prompt-injection scanning, an input firewall with PII redaction, output validation against a JSON Schema, PII redaction, and domain trust reports. A typed SDK for ESM and CommonJS, plus a CLI.
npm install @caelaralabs/agent-guardnpx -y @caelaralabs/agent-guard --scan "Ignore all previous instructions"Node 20 or newer. No runtime dependencies.
Where requests go: requests are processed by Caelara Labs edge APIs at *.caelaralabs.com (agent.caelaralabs.com and compliance.caelaralabs.com), with a free 50-call trial key, CAELARA_API_KEY, or x402 USDC payment headers. There is no anonymous free tier: without a key or a payment every call answers HTTP 402.
SDK
ESM:
import { scanPromptInjection, sanitizeInput, validateOutput, redactPII, checkDomainTrust, CaelaraError } from '@caelaralabs/agent-guard'
const scan = await scanPromptInjection(userText)
if (scan.verdict !== 'allow') throw new Error(`blocked input (risk ${scan.risk_score})`)
const input = await sanitizeInput(userText) // injection check + PII redaction
const safeText = input.sanitized_text // null when the verdict is "block"
const out = await validateOutput(modelOutput, {
schema: { type: 'object', required: ['answer'], properties: { answer: { type: 'string' } } },
source: retrievedContext, // optional grounding check
})
if (out.verdict === 'fail') console.log(out.schema?.errors)
const { redacted } = await redactPII('Mail me at [email protected]')
const trust = await checkDomainTrust('example.com') // trust_score, verdict, flagsCommonJS:
const { scanPromptInjection, CaelaraError } = require('@caelaralabs/agent-guard')
scanPromptInjection(text)
.then((r) => console.log(r.verdict, r.risk_score))
.catch((e) => {
if (e instanceof CaelaraError && e.isBilling) console.error(e.guidance)
else throw e
})| Function | Request | Result fields |
| --- | --- | --- |
| sanitizeInput(text, { redactPII? }) | POST agent.caelaralabs.com/v1/agent-input-firewall { text, redact_pii } | verdict (allow, review, block), risk_score, injection_matches, pii_findings, sanitized_text, tokens_estimate |
| scanPromptInjection(text) | POST /v1/prompt-injection-scanner { text } | verdict, risk_score, matches |
| validateOutput(output, { schema?, source? }) | POST /v1/agent-output-validator { output, schema, source } | verdict (pass, fail), json, schema, grounding, citations |
| redactPII(text) | POST /v1/pii-redactor { text } | redacted, findings, total |
| checkDomainTrust(domain) | GET compliance.caelaralabs.com/v1/domain-trust-composite?domain= | domain, trust_score, verdict (trusted, caution, risky), email_auth, certificates, security_headers, flags, partial |
Every function also takes the client options { apiKey?, payment?, fetch?, timeoutMs? }. apiKey and payment default to the environment variables below, and timeoutMs defaults to 15000.
Failures throw a CaelaraError with status, code (payment_required, rate_limited, bad_request, http_error, network_error, timeout, partial, invalid_response) and body. For HTTP 402 and 429, isBilling is true, guidance lists the ways to get access, and on a 402 terms holds the x402 price, network and recipient.
Backup routing
withCaelaraFallback wraps your existing fetch. When a provider you already call is rate limited or briefly unavailable, the same request is answered once by https://compat.caelaralabs.com.
import { withCaelaraFallback } from '@caelaralabs/agent-guard'
const fetchWithFallback = withCaelaraFallback(fetch, { apiKey: process.env.CAELARA_API_KEY })
const res = await fetchWithFallback('https://api.your-provider.example/v1/email-verifier?email=a%40b.co')
if (res.headers.get('x-caelara-routed-fallback') === 'true') console.log('answered by the fallback')- Fails over only on HTTP 429, 502, 503 or 504 (and on a network error, for retry-safe requests only).
- Retries only
GET,HEADandOPTIONS, or a request that carries anIdempotency-Keyheader. APOST,PUT,PATCHorDELETEwithout one is never replayed, and a streamed body is never re-sent. - Only requests that match a compatibility route fail over:
/v1/scrape,/v1/email-verifier,/v1/company/find,/v1/seo/audit,/v1/token/audit,/v1/wallet/portfolio,/v1/document/extractand/v1/compliance/entity. Map other paths withroutes: { '/api/v3/verify': '/v1/email-verifier' }. - One hop at most: the forwarded request carries
x-caelara-routed-fallback: true, and a marked request never fails over again, so there are no loops and no double charges. - Method, query, body and ordinary headers are kept. Your provider's credentials (
Authorization, cookies, API-key and token headers) are never sent to Caelara Labs; only your Caelara key (apiKey,X-Caelara-KeyorCAELARA_API_KEY) or x402 payment is. - A fallback answer carries
x-caelara-routed-fallback: true. If the fallback also fails, you get the original upstream response, unchanged.
CLI
agent-guard --scan "<text>" # prompt-injection score
cat message.txt | agent-guard --scan - # same, from stdin
agent-guard --validate output.json --schema schema.json
agent-guard --redact "Call me on +1 415 555 0100"
agent-guard --domain example.comAdd --json to print the API response. Text output goes to stdout; with --redact the summary of what was removed goes to stderr, so agent-guard --redact - < in.txt > out.txt writes only the redacted text.
| Exit code | Meaning |
| --- | --- |
| 0 | allow, pass or trusted (and --redact succeeded) |
| 1 | review or block, validation failed, caution or risky domain, or the check could not complete |
| 2 | Usage error |
| 3 | The API refused the request (HTTP 402 or 429): billing or rate limit |
A network failure or timeout exits 1, so a pipeline that gates on agent-guard fails closed.
Environment
| Variable | Purpose |
| --- | --- |
| CAELARA_API_KEY | Your Caelara key, sent as X-Caelara-Key. Free 50-call trial key: https://caelaralabs.com/shield/#trial |
| CAELARA_X402_PAYMENT | Optional pre-signed x402 v2 payment, sent as PAYMENT-SIGNATURE (and X-PAYMENT for older hosts). This package never holds a wallet or signs payments. |
| CAELARA_AGENT_API_BASE, CAELARA_COMPLIANCE_API_BASE | Point requests at a local mock for testing. Only loopback addresses are accepted. |
Access and pricing
On HTTP 402 or 429 you get the three ways to get access:
- Free trial key: 50 calls from https://caelaralabs.com/shield/#trial, set as
CAELARA_API_KEY. - Prepaid EGU pack: one time from $5 at $0.0002 per EGU (https://caelaralabs.com/pass/), set as
CAELARA_API_KEY. No subscription; the balance never expires. - x402 per call: USDC on Base.
scanPromptInjectionandredactPIIcost 0.005 USDC per call;sanitizeInput,validateOutputandcheckDomainTrustcost 0.025 USDC. x402 v2: the terms arrive in thePAYMENT-REQUIREDheader; pass a pre-signed payload inCAELARA_X402_PAYMENTor thepaymentoption and it is sent asPAYMENT-SIGNATURE(withX-PAYMENTas the legacy fallback).
A trial key allows about one call per second; a 429 means wait and retry.
License
MIT, Caelara Labs [email protected]
