Hiding tool call results from streamText in AI SDK

I am building an app with the ai-sdk, and I am using the streamText function to stream messages to the frontend. However, I noticed that the results of tool calls are also being sent to the frontend.

Is there a way to restrict or control which tool results are sent to the frontend?

Code Example

const result = streamText({
  model: groq("moonshotai/kimi-k2-instruct-0905"),
  tools,
  stopWhen: stepCountIs(5),
  messages: modelMessages,
});

result.pipeUIMessageStreamToResponse(res, {
  onFinish({ responseMessage }) {
    console.log("Response message: ", responseMessage);
  },
});

Before sending the response to the frontend, just modify the tool parts and hide their output. For example:

onFinish: async ({ messages, responseMessage }) => {
responseMessage.parts = responseMessage.parts.map((part) => {
if (
part.type.startsWith("tool-") &&
part.state === "output-available"
) {
return {
...part,
output: "[REDACTED]",
};
}
return part;
});
},