Agent incident playbook · practical first
JSONDecodeError in an AI agent?
Identify broken JSON before you pay to normalize it.
Fix it first
- Inspect the actual response status and Content-Type. A 200 response can still be HTML, an empty body or an error envelope.
- Save a sanitized sample of the response and reproduce it with a deterministic parser. Never run untrusted model output as executable code.
- Validate the expected object schema after parsing; syntactically valid JSON can still contain the wrong fields.
Safe starter code
const response = await fetch(url, { signal: AbortSignal.timeout(15000) });
const type = response.headers.get('content-type') || '';
const raw = await response.text();
if (!response.ok || !type.includes('application/json')) {
throw new Error('Expected JSON response, got HTTP ' + response.status);
}
let parsed;
try { parsed = JSON.parse(raw); }
catch { throw new Error('Invalid JSON payload'); }
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new Error('Expected JSON object');
}Illustrative code. Adapt persistence, request validation, authorization and provider APIs to your production environment. No payments are performed by this example.
Optional HumanMirror service
Clean JSON — 0.010 USDC per explicitly authorized call on Base. The live HTTP 402 response is authoritative; an independent buyer must authorize each paid request.
See live pricing & integrationsService endpoint (POST)Integration guideScoped B2B help
Want a human-reviewed fixed-scope report instead of another tool? The Agent Safety Audit is €299, the 14-day Production Pilot €990. Confirm scope and acceptance criteria before purchasing.
€299 audit — Stripe checkout€990 pilot — Stripe checkout