# Agent402 SQL Guard

> Agent402 SQL Guard is a paid API for AI agents from agent402.tools, paid per call via x402, $0.004/call, status unknown (last checked 2026-09-15).

Validates and risk-audits a SQL statement before execution, returning a signed certificate and verdict indicating whether the query is safe to run.

## Facts

- Endpoint: POST https://agent402.tools/api/sql-guard
- Price: $0.004/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/agent402-sql-guard-b4d89e4c
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_9zz12F7lu5XPhHT1Ng_54

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability agent402-sql-guard-b4d89e4c -d '<json body>'
```

Example prompt: Before I run this query against the database, check if it's safe: SELECT * FROM users WHERE id = 42 — use a 5-minute certificate lifetime and flag any risks you find.

## When to prefer this

Use this endpoint when an AI agent or application dynamically generates SQL and needs a security checkpoint before execution — especially to prevent injection attacks, accidental destructive queries, or unauthorized mutations. Prefer this over manual review when you need a machine-readable verdict and a cryptographically signed certificate to enforce pre-approval in downstream systems. Ideal for agentic pipelines where SQL is generated from natural language and must be audited before touching a production database.

## Known failure modes

- SQL contains multiple statements without allowMultiStatement=true → returns block verdict or error
- High-risk operation (e.g. DROP, TRUNCATE) not in allow list → verdict='block'
- Invalid or empty SQL string → validation error response
- TTL outside 30–3600 range → parameter error
- Payment not received or insufficient → x402 payment required response
- Malformed JSON body → HTTP 400 bad request

## How this service works

Review a SQL statement before running it against production: a pass / warn / block verdict naming concrete risks (unbounded UPDATE or DELETE, tautological WHERE, DROP, TRUNCATE, statement stacking, privilege changes, catalog writes) and, on pass, an Ed25519 certificate bound to the statement's SHA-256 that a database layer can verify before executing. Use it as the last check between an agent and a destructive query.

## Output

Returns a JSON object with a verdict ('pass', 'warn', or 'block'), a list of detected risks with IDs, a SHA-256 hash of the submitted statement, a flag indicating whether the statement is mutating, the count of statements detected, and a signed certificate token with an expiry timestamp that downstream systems can use to prove the SQL was pre-audited.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "sql": {
   "type": "string",
   "description": "the exact statement you are about to execute"
  },
  "allow": {
   "type": "array",
   "description": "risk ids to downgrade from block to warn (see riskCatalogue in the response)"
  },
  "ttlSeconds": {
   "type": "number",
   "description": "certificate lifetime, 30-3600 (default 300)"
  },
  "allowMultiStatement": {
   "type": "boolean",
   "description": "permit more than one statement in the submission (default false)"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "risks": [],
  "sha256": "635cf20a…",
  "verdict": "pass",
  "mutating": true,
  "certificate": {
   "token": "eyJ2Ijox….signature",
   "expiresAt": "2026-07-28T20:05:00Z"
  },
  "statementCount": 1
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/agent402-sql-guard-b4d89e4c/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agent402.tools](https://www.zero.xyz/host/agent402.tools/llms.txt)
