[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[AI SDK](/c/ai-sdk/62)

# Hiding tool call results from streamText in AI SDK

32 views · 0 likes · 2 posts


Dinesh882002 (@dinesh882002) · 2026-03-08

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

```tsx
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);
  },
});
```


mo0hie (@m-416u) · 2026-04-07

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;`
`       });`
`    },`