LLM tools wrap the Document API
Every LLM tool call maps to a Document API operation under the hood.superdoc_edit with action: "replace" calls the same function as doc.replace().
This gives you a clear debugging strategy:
- 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.
- If the API call fails, the issue is in the operation itself — check arguments, targets, and document state.
- 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.
Log tool calls and results
Add logging arounddispatchSuperDocTool to see exactly what the model is requesting and what comes back.
- Tool name — is the model calling the right tool?
- Arguments — are required fields present? Is the
actioncorrect? - Targets — are handles/addresses from a recent search, or did the model guess?
- Result — did the operation return data or an error?
Error shapes
dispatchSuperDocTool throws errors in two categories:
Validation errors — bad arguments before the operation runs:
err.message. Pass them back as tool results — the model usually self-corrects.
Common failure modes
| Symptom | Cause | Fix |
|---|---|---|
| Model calls the wrong tool | System prompt missing or too vague | Use getSystemPrompt() or add workflow instructions |
| ”Target not found” errors | Model uses stale or guessed handles | Instruct model to always search before editing |
| Edits land in the wrong place | Model invented a block address | Use superdoc_search to get fresh handles |
| Infinite tool call loop | Model never reaches a stopping point | Add a max iterations guard (see below) |
| Model doesn’t use tools at all | Tools not passed to the API call | Verify chooseTools() result is in the tools param |
| ”Missing required parameter” | Model forgot action or another field | Check the tool schema — add examples to the prompt |
| Collaboration edits not appearing | SDK not in the same collab room | Verify the collaboration URL and documentId match |
| Operation works via API but fails via tool | Model passes wrong argument types/names | Log the parsed arguments and compare to the API signature |
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:Related
- LLM tools — tool catalog and SDK functions
- How to use — step-by-step integration guide
- Best practices — prompting and workflow tips
- Document API — the underlying operations that tools call

