Skip to content

V38: Let createAgent sanitize tool error text sent to the model - #694

Merged
LinuxDevil merged 2 commits into
mainfrom
v38-tool-error-message
Oct 20, 2026
Merged

LinuxDevil merged 2 commits into
mainfrom
v38-tool-error-message

Conversation

@LinuxDevil

Copy link
Copy Markdown
Owner

Fixes audit finding AI-9 (Vercel competitor audit, 2026-10-19).

What was wrong

A tool that throws new Error("DB password=hunter2 connection refused") sent that text verbatim to the model and the event stream; there was no hook to redact it.

What changed

  • New opt-in createAgent({ toolErrorMessage: (error, { toolName, toolCallId }) => string }) (also an ExecuteOptions field, inherited by sub-agents, and honored on the post-approval resume path).
  • Its return value replaces message for kind: 'execution' errors. The same sanitized text reaches tool.error events, onToolResult and postToolCall hooks, so client-facing streams never carry the original; only the sanitizer sees the thrown error (log it there).
  • Validation errors and other kinds (mcp, sandbox, ...) are untouched. A throwing or non-string-returning sanitizer yields The tool failed.; the run continues.
  • Key added to the createAgent allowlist; docs (tools.md Errors, configuration.md), llms and api reports updated.

Tests

toolErrorResult.test.ts: secret text replaced for model and tool.error event (kind stays execution); validation error untouched and sanitizer not called; throwing sanitizer gives generic message and run completes; no option behaves as before. Ran tsc, typecheck:tests, lint, api:check, docs:llms:check, fallow (exit 0) and test:coverage; the coverage run's only failures were load/Windows flakes (wrangler dev, tracing, kit-pi) that pass in isolation.

Changelog: Added createAgent({ toolErrorMessage }) to sanitize thrown tool error text before it reaches the model, events and hooks.

🤖 Generated with Claude Code

@LinuxDevil
LinuxDevil force-pushed the v38-tool-error-message branch from 852ee02 to f6eee8c Compare October 20, 2026 03:27
LinuxDevil and others added 2 commits October 20, 2026 09:50
Adds an opt-in createAgent({ toolErrorMessage }) that replaces the message of
a thrown tool error (kind 'execution') before the model, tool.error events and
hooks see it. A throwing sanitizer yields a generic message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LinuxDevil
LinuxDevil force-pushed the v38-tool-error-message branch from 979b332 to de08fb3 Compare October 20, 2026 06:54
@LinuxDevil
LinuxDevil merged commit ada1847 into main Oct 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant