Function: toolError()
ts
function toolError(code, options): ToolResponse;Defined in: packages/core/src/core/response.ts:354
Create a self-healing error response with recovery instructions.
Unlike error, this provides structured guidance so the LLM agent can self-correct instead of hallucinating or giving up. The response includes an error code, message, suggestion, and available actions — all formatted for optimal LLM comprehension.
Parameters
| Parameter | Type | Description |
|---|---|---|
code | ErrorCode | Short error code (e.g. 'ProjectNotFound', 'Unauthorized') |
options | ToolErrorOptions | Error details and recovery instructions |
Returns
A ToolResponse with isError: true and recovery guidance
Examples
typescript
handler: async (ctx, args) => {
const project = await ctx.db.get(args.project_id);
if (!project) {
return toolError('ProjectNotFound', {
message: `Project '${args.project_id}' does not exist.`,
suggestion: 'Call projects.list first to get valid IDs, then retry.',
availableActions: ['projects.list'],
});
}
return success(project);
}typescript
// Minimal usage (no suggestion)
return toolError('RateLimited', {
message: 'Too many requests. Wait 30 seconds.',
});