Skip to content

fix(anthropic): handle web_fetch error result JSON parsing gracefully#11857

Merged
aayush-kapoor merged 4 commits intovercel:mainfrom
codicecustode:fix/anthropic-web-fetch-error-handling
Jan 20, 2026
Merged

fix(anthropic): handle web_fetch error result JSON parsing gracefully#11857
aayush-kapoor merged 4 commits intovercel:mainfrom
codicecustode:fix/anthropic-web-fetch-error-handling

Conversation

@codicecustode
Copy link
Copy Markdown
Contributor

Background

Anthropic’s web_fetch tool can return typed error results (e.g., web_fetch_tool_result_error). These were causing a crash during prompt serialization because convertToAnthropicMessagesPrompt attempted JSON.parse on an object value, producing "[object Object]" is not valid JSON.

Summary

  • Handle web_fetch error results when output.value is either a string or an object, defaulting error_code to 'unknown' on malformed JSON.
  • Added tests covering object-form and malformed-string error values.
  • Added a patch changeset for @ai-sdk/anthropic.

Manual Verification

  • Ran package tests: pnpm test:node and pnpm test:edge in packages/anthropic.
  • Confirmed new web_fetch error-handling tests pass.

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

  • None.

Related Issues

@vercel-ai-sdk vercel-ai-sdk bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Jan 18, 2026
@aayush-kapoor aayush-kapoor enabled auto-merge (squash) January 20, 2026 20:49
@aayush-kapoor aayush-kapoor merged commit 4729bed into vercel:main Jan 20, 2026
18 of 19 checks passed
B-Step62 pushed a commit to B-Step62/ai that referenced this pull request Jan 28, 2026
…vercel#11857)

## Background
Anthropic’s `web_fetch` tool can return typed error results (e.g.,
`web_fetch_tool_result_error`). These were causing a crash during prompt
serialization because `convertToAnthropicMessagesPrompt` attempted
`JSON.parse` on an object value, producing `"[object Object]" is not
valid JSON`.

## Summary
- Handle `web_fetch` error results when `output.value` is either a
string or an object, defaulting `error_code` to `'unknown'` on malformed
JSON.
- Added tests covering object-form and malformed-string error values.
- Added a patch changeset for `@ai-sdk/anthropic`.

## Manual Verification
- Ran package tests: `pnpm test:node` and `pnpm test:edge` in
`packages/anthropic`.
- Confirmed new web_fetch error-handling tests pass.

## Checklist
- [x] Tests have been added / updated (for bug fixes / features)
- [ ] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [x] I have reviewed this pull request (self-review)

## Future Work
- None.

## Related Issues
- Fixes vercel#11856

---------

Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/anthropic Issues related to the @ai-sdk/anthropic provider

Projects

None yet

2 participants