Handling user denial for client-side tool calls in the Vercel AI SDK

Hi,

When handling client-side tool calls, is there a recommended way to propagate a user denial in the same way as with server-side tool calls?

I noticed that UIToolInvocation state seems to include output-denied, but it doesn’t appear that this can be set via addToolOutput().

Would addToolApprovalResponse() be the correct approach here?
However, that function seems to be intended only for server-side tool calls.

Alternatively, if I return an appropriate error via addToolOutput(), will the LLM properly interpret that as the tool invocation being denied by the user?

Thanks in advance.

The ‘output-denied’ state you noticed in UIToolInvocation is an internal state used by the framework, not something you can set directly. For client-side tools, you can use the output-error state:

addToolOutput({
  tool: 'yourToolName',
  toolCallId: invocation.toolCallId,
  state: 'output-error',
  errorText: 'Tool execution denied by user'
})

That tells the LLM that the tool execution failed, and it will handle it appropriately. This is semantically correct since from the tool’s perspective, a user denial is effectively an execution failure.

I hope that helps!

1 Like

It works well. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.