Skip to main content
When tool calls fail or produce unexpected results, use these patterns to diagnose the issue.

LLM tools wrap the Document API

Every LLM tool call maps to a Document API operation under the hood. On the core preset, superdoc_perform_action with action: "replace_text" resolves its targets and then runs the same operations as doc.replace(); on legacy, superdoc_edit with action: "replace" calls it directly. This gives you a clear debugging strategy:
  1. Test the Document API directly. Call the underlying SDK method with the same arguments. If it works, the operation is fine: the problem is in the prompt or the tool schema.
  2. If the API call fails, the issue is in the operation itself: check arguments, targets, and document state.
  3. If the API call succeeds but the LLM tool call fails, the model is calling the tool incorrectly. Fix the prompt, add examples, or check the tool schema.
This narrows every issue to one of two layers: the operation or the prompt.

Log tool calls and results

Add logging around dispatchSuperDocTool to see exactly what the model is requesting and what comes back.
dispatchSuperDocTool(doc, name, args) without options dispatches against the legacy default. Pass { preset: 'core' } when your tools came from the core preset — or use the toolkit’s pre-bound dispatch, which can’t mismatch. The examples below assume core.
What to look for in logs:
  • Tool name: is the model calling the right tool?
  • Arguments: are required fields present? Is the action correct?
  • Targets: are handles/addresses from a recent search, or did the model guess?
  • Result: did the operation return data or an error?

Read the receipt first (core preset)

On the core preset, most “failures” aren’t thrown errors — they’re receipts doing their job. Before reaching for logs:
  • status: "failed" + errors[].code: "MATCH_NOT_FOUND" — the target text/element wasn’t found and nothing was changed. The message names what to fix; recovery is machine-usable (reinspect / retry / revert with a paste-ready call).
  • status: "partial" — part of the batch landed; the receipt reports which part (editsApplied / editsSkipped, capped lists with *Count totals). Re-inspect, then fix forward.
  • verificationPassed: false on an ok receipt — the edit applied but a post-check (placement adjacency, count delta) disagreed; the verification array shows which check.
  • INVALID_ARGUMENT with excluded: true — the action is excluded by your excludeActions configuration, not broken.
Feeding the whole receipt back as the tool result is usually all the “debugging” the model needs.

Error shapes

dispatchSuperDocTool throws errors in two categories: Validation errors: bad arguments before the operation runs:
Execution errors: the operation ran but failed:
Both types are returned as strings in err.message. Pass them back as tool results: the model usually self-corrects.

Common failure modes

Shared (either preset): Core preset: Legacy preset:

Inspect tools directly

Dump the tool schemas to verify the SDK loaded correctly:

Max iterations guard

Prevent runaway loops by capping the number of iterations: