See what is happening
Optional hooks to know when EDcheck calls the AI, what it answered, or if it failed.
EDcheck does not write to the console. If you want logs or traces, you attach them with hooks.
There are three: onRequest, onResponse, and onError. Each one runs once per provider request. If a parse does not need the AI (because Zod already rejected everything), none of them run.
Simple example
const edcheck = createEDcheck({ provider, hooks: { onRequest: (event) => { console.log("asking", event.ruleIds); }, onResponse: (event) => { console.log("done", event.outcomes, event.durationMs); }, onError: (event) => { console.log("failed", event.kind); }, },});What each event carries
| Field | Meaning |
|---|---|
parseId | One id per safeParse. |
requestId | One id per provider call. |
requestIndex / requestCount | This is request 1 of N for that parse. |
provider | The name (typesafe, gateway, mock). |
entry | object or node, depending on how you validated. |
ruleIds | Which rules went in this request. |
durationMs | How long it took (on the response or the error). |
outcomes | pass / warning / fail per rule, before issues are built. |
kind | On onError: provider, abort, or unexpected. |
Two things to watch
- If your hook throws, EDcheck swallows it and will not tell you. Test your hooks.
- The event includes the full
request, includingstate. If you export this to a logger, strip sensitive data first.
If a parse opens several requests, wait for requestCount terminal events (onResponse or onError) with the same parseId. Then you know that parse is done talking to the AI.