Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

AI SDK tool spans don't respect `toModelOutput`

已关闭
#2,651 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@AbhiPrasad 已经在做这个了。

开始于 2026年10月22日。

  • #2652 来自 @AbhiPrasad —— 已合并

评估

这个 Issue 还没有评估数据。

描述

typescript

When a Vercel AI SDK tool defines toModelOutput, the model only sees that transformed value, but the wrapAISDK tool span still logs the raw execute result via the patched execute.

Apps use toModelOutput to keep data away from the model, for example query rows a user hasn't agreed to share. Braintrust's global setMaskingFunction doesn't fix this cleanly, because it doesn't know which tool a value came from.

Repro with [email protected] and [email protected], using a mock model:

import * as ai from 'ai'
import { MockLanguageModelV4 } from 'ai/test'
import { initLogger, wrapAISDK } from 'braintrust'
import { z } from 'zod'

initLogger({ projectName: 'repro' })
const { generateText } = wrapAISDK(ai)

await generateText({
  model: new MockLanguageModelV4({
    doGenerate: async () => ({
      content: [{ type: 'tool-call', toolCallId: 'call-1', toolName: 'runQuery', input: '{}' }],
      finishReason: { unified: 'tool-calls', raw: undefined },
      usage: { inputTokens: { total: 1 }, outputTokens: { total: 1 } },
      warnings: [],
    }),
  }),
  prompt: 'Count signups',
  tools: {
    runQuery: ai.tool({
      inputSchema: z.object({}),
      execute: async () => ({ rows: [{ email: '[email protected]' }] }),
      toModelOutput: () => ({ type: 'text', value: 'Rows hidden from the model' }),
    }),
  },
})

The runQuery tool span's output is { rows: [{ email: '[email protected]' }] }. I expected Rows hidden from the model. The raw rows also appear in the parent generateText span, under steps[].content[] in the tool result. The same happens with ai.registerTelemetry(braintrustAISDKTelemetry()).

tool span parent span
Image Image

When a tool defines toModelOutput, I expect the tool span and the parent span's tool results to log its result instead of the raw execute value. That way the trace matches what the model saw and avoids privacy footguns. If this is too big a change for the default, a wrapAISDK option to turn it on would cover our case.

主要语言
TypeScript
星标
29
派生
21
平均合并
1 天 12 小时
30 天内合并 PR
70

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

braintrustdata/braintrust-sdk-javascript 的其他 Issue

查看 braintrustdata/braintrust-sdk-javascript 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。