Skip to content

Skill: Schema guard

FREE with proof-of-workor $0.004 in USDCPOST /api/skill/schema-guard

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...

Category: Skill packsTags: skill-pack workflow schema-guardPack overview

Try in playground →

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

NameTypeRequiredDescription
payloadstringyesThe JSON payload to check (as a JSON string) Also accepted as body, data, claims, message. The example sends {"id":1,"name":"Ada"}.
schemastringnoThe 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

RequestPOST /api/skill/schema-guard
402$0.004 USDC
SignPAYMENT-SIGNATURE
Settleon 14 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

Example 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"
}
FieldTypeAlways presentIn the example
packstringyesschema-guard
argsobjectyes2 fields: payload, schema
stepsarray of objectsyes4 items in the example
summarystringyes4/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

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.

Related tools