# Patch Guard – Safe JSON Patch Evaluation

> Patch Guard – Safe JSON Patch Evaluation is a paid API for AI agents from patch-guard-api.me-e51.workers.dev, paid per call via x402, $0.01/call, status unknown (last checked 2026-09-14).

Atomically applies RFC 6902 JSON Patch operations to a document, validates the result against an optional JSON Schema, enforces protected-path constraints, and returns a verdict, inverse patch, normalized diff, and SHA-256 hashes.

## Facts

- Endpoint: POST https://patch-guard-api.me-e51.workers.dev/v1/patch-guard
- Price: $0.01/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/patch-guard-safe-json-patch-evaluation-e06bcd9a
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_Tk1mEidwUTQxRDLcMPRT9

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 patch-guard-safe-json-patch-evaluation-e06bcd9a -d '<json body>'
```

Example prompt: Apply these three JSON Patch operations — replace /profile/role from 'reader' to 'writer' and increment /revision from 7 to 8 — to this user document, make sure /id and /createdAt are protected and can't be touched, validate the result against this JSON Schema draft 2020-12, and tell me whether to allow or deny the patch plus give me the inverse patch to roll it back.

## When to prefer this

Choose this endpoint when you need to safely evaluate RFC 6902 JSON Patch operations without touching your real data store — especially when protected fields must be enforced, schema conformance of the result must be verified, or you need an automatic inverse patch for rollback. It is preferable to a plain patch library when atomicity guarantees, path protection, and audit artifacts (sha256, normalized diff) are required in a single call.

## Known failure modes

- Request body exceeds 64 KiB — rejected before billing
- Patch contains more than 100 operations — rejected
- Protected paths list exceeds 100 entries — rejected
- Schema uses disallowed keywords (regex, $ref, combinators, conditionals) — rejected before billing
- Malformed RFC 6901 JSON Pointer in path or from fields — validation error
- Invalid op value outside allowed enum — schema rejection
- Test operation fails mid-patch — atomic rollback, patchValid: false returned
- Payment not included or insufficient USDC — x402 payment required response

## How this service works

Four x402-paid agent utilities: safe JSON Patch evaluation, multi-source crypto price consensus, normalized Polymarket movers, and deterministic JSON repair/canonicalization.

## Output

Returns a JSON object containing: a verdict ('allow' or 'deny'), patchValid and schemaValid booleans, a violations array listing any protected-path or schema breaches, the patched result document, an inversePatch array to undo the change, a normalizedDiff array, SHA-256 hashes of the original and patched documents, and a limits summary showing operation counts and schema errors.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "patch": {
   "type": "array",
   "items": {
    "type": "object",
    "required": [
     "op",
     "path"
    ],
    "properties": {
     "op": {
      "enum": [
       "add",
       "remove",
       "replace",
       "move",
       "copy",
       "test"
      ],
      "type": "string"
     },
     "from": {
      "type": "string",
      "description": "Source pointer for move or copy."
     },
     "path": {
      "type": "string",
      "description": "RFC 6901 JSON Pointer."
     },
     "value": {
      "description": "Value for add, replace, or test."
     }
    }
   },
   "maxItems": 100,
   "description": "RFC 6902 operations, applied atomically to an isolated clone."
  },
  "schema": {
   "oneOf": [
    {
     "type": "object"
    },
    {
     "type": "boolean"
    }
   ],
   "description": "Optional bounded JSON Schema subset evaluated against the patched result. References, regex-bearing, combinator, conditional, and unbounded-uniqueness keywords are rejected before billing."
  },
  "document": {
   "description": "The JSON value to patch. Maximum total request size is 64 KiB."
  },
  "schemaDraft": {
   "enum": [
    "4",
    "7",
    "2019-09",
    "2020-12"
   ],
   "type": "string",
   "default": "2020-12"
  },
  "protectedPaths": {
   "type": "array",
   "items": {
    "type": "string"
   },
   "maxItems": 100,
   "description": "Pointers that the patch may not mutate. Ancestor replacement is blocked too."
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "atomic": true,
  "limits": {
   "protectedPaths": 1,
   "patchOperations": 3,
   "schemaErrorsReturned": 0
  },
  "result": {
   "profile": {
    "name": "Ada",
    "role": "writer"
   },
   "revision": 8
  },
  "verdict": "allow",
  "patchValid": true,
  "violations": [],
  "schemaValid": true,
  "inversePatch": [
   {
    "op": "test",
    "path": "/revision",
    "value": 8
   },
   {
    "op": "replace",
    "path": "/revision",
    "value": 7
   },
   {
    "op": "test",
    "path": "/profile/role",
    "value": "writer"
   },
   {
    "op": "replace",
    "path": "/profile/role",
    "value": "reader"
   }
  ],
  "resultSha256": "sha256:...",
  "normalizedDiff": [
   {
    "op": "test",
    "path": "/revision",
    "value": 7
   },
   {
    "op": "replace",
    "path": "/revision",
    "value": 8
   },
   {
    "op": "test",
    "path": "/profile/role",
    "value": "reader"
   },
   {
    "op": "replace",
    "path": "/profile/role",
    "value": "writer"
   }
  ],
  "originalSha256": "sha256:...",
  "artifactsComplete": true
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/patch-guard-safe-json-patch-evaluation-e06bcd9a/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from patch-guard-api.me-e51.workers.dev](https://www.zero.xyz/host/patch-guard-api.me-e51.workers.dev/llms.txt)
