Skill: Schema guard
POST /api/skill/schema-guardContract-test a JSON payload in one call: validate it against your schema, infer the schema the payload actually implies, diff the two to expose drift...
Details
Contract-test a JSON payload in one call: validate it against your schema, infer the schema the payload actually implies, diff the two to expose drift, and return a normalized pretty-print. Schema guard skill pack: one x402 payment runs 4 underlying tools (json-validate, json-schema-infer, json-diff, json-format); partial-success per step.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
payload | string | yes | The JSON payload to check (as a JSON string) Also accepted as body, data, claims, message. The example sends {"id":1,"name":"Ada"}. |
schema | string | no | The expected JSON Schema (as a JSON string; defaults to none) The example sends {"type":"object","required":["id"]}. |
Free call, no wallet
Fetch a challenge, solve its sha256 puzzle (16 leading zero bits), resend with X-Pow-Solution.
import { createHash } from "node:crypto";
const lz = (b) => { let t = 0; for (const x of b) { if (!x) { t += 8; continue; } t += Math.clz32(x) - 24; break; } return t; };
const c = await (await fetch("https://agent402.tools/api/pow/challenge?slug=skill-schema-guard")).json();
let n = 0;
while (lz(createHash("sha256").update(c.challenge + ":" + n).digest()) < c.difficulty) n++;
await fetch("https://agent402.tools/api/skill/schema-guard", { method: "POST", headers: { "X-Pow-Solution": c.token + ":" + n, "Content-Type": "application/json" }, body: JSON.stringify({"payload":"{\"id\":1,\"name\":\"Ada\"}","schema":"{\"type\":\"object\",\"required\":[\"id\"]}"}) });Python:
import hashlib, json, urllib.request
def zero_bits(digest):
n = 0
for b in digest:
if b:
return n + 8 - b.bit_length()
n += 8
return n
c = json.load(urllib.request.urlopen("https://agent402.tools/api/pow/challenge?slug=skill-schema-guard"))
n = 0
while zero_bits(hashlib.sha256(f"{c['challenge']}:{n}".encode()).digest()) < c["difficulty"]:
n += 1
req = urllib.request.Request("https://agent402.tools/api/skill/schema-guard", method="POST", data="{\"payload\":\"{\\\"id\\\":1,\\\"name\\\":\\\"Ada\\\"}\",\"schema\":\"{\\\"type\\\":\\\"object\\\",\\\"required\\\":[\\\"id\\\"]}\"}".encode(), headers={"X-Pow-Solution": f"{c['token']}:{n}", "Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(req)))Example request
curl -i -X POST https://agent402.tools/api/skill/schema-guard \
-H "Content-Type: application/json" \
-d '{"payload":"{\"id\":1,\"name\":\"Ada\"}","schema":"{\"type\":\"object\",\"required\":[\"id\"]}"}'Watch a call get paid
POST /api/skill/schema-guard$0.004 USDCPAYMENT-SIGNATUREon 14 chains200 OKAgent402-ReceiptEd25519Example response
{
"pack": "schema-guard",
"args": {
"payload": "{\"id\":1,\"name\":\"Ada\"}",
"schema": "{\"type\":\"object\",\"required\":[\"id\"]}"
},
"steps": [
{
"slug": "json-validate",
"ok": true,
"result": {}
},
{
"slug": "json-schema-infer",
"ok": true,
"result": {}
},
{
"slug": "json-diff",
"ok": true,
"result": {}
},
{
"slug": "json-format",
"ok": true,
"result": {}
}
],
"summary": "4/4 steps succeeded"
}| Field | Type | Always present | In the example |
|---|---|---|---|
pack | string | yes | schema-guard |
args | object | yes | 2 fields: payload, schema |
steps | array of objects | yes | 4 items in the example |
summary | string | yes | 4/4 steps succeeded |
From an MCP client
catalog.call {
"slug": "skill-schema-guard",
"params": {
"payload": "{\"id\":1,\"name\":\"Ada\"}",
"schema": "{\"type\":\"object\",\"required\":[\"id\"]}"
}
}Hosted connector (https://agent402.tools/mcp): free, rate-limited. Stdio package: npx -y agent402-mcp@0.17.2.
Errors and behavior
- Pay $0.004 per call over x402 or MPP, or free with proof-of-work (16 leading zero bits of sha256): this tool makes no outbound network call.
- Arguments left out take the pack's defaults. The call succeeds when at least one step does; a run where every step fails is refused (400 when the input caused it, 502 otherwise).
- On this route, a call ending in any status of 400 or above is not charged over x402, MPP or a credits key. A Tempo push credential pays before the call; a failure is a refund owed.
- A bodyless
GETorHEADreturns the same 402 quote. - An
Idempotency-Keyreplays the first 200 uncharged (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.004" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/skill/schema-guard", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"payload": "{\"id\":1,\"name\":\"Ada\"}",
"schema": "{\"type\":\"object\",\"required\":[\"id\"]}"
}),
});Get a wallet or run npx -y agent402-mcp@0.17.2 wallet new.