fix(anthropic): handle web_fetch error result JSON parsing gracefully#11857
Merged
aayush-kapoor merged 4 commits intovercel:mainfrom Jan 20, 2026
Merged
Conversation
aayush-kapoor
approved these changes
Jan 20, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Anthropic’s
web_fetchtool can return typed error results (e.g.,web_fetch_tool_result_error). These were causing a crash during prompt serialization becauseconvertToAnthropicMessagesPromptattemptedJSON.parseon an object value, producing"[object Object]" is not valid JSON.Summary
web_fetcherror results whenoutput.valueis either a string or an object, defaultingerror_codeto'unknown'on malformed JSON.@ai-sdk/anthropic.Manual Verification
pnpm test:nodeandpnpm test:edgeinpackages/anthropic.Checklist
pnpm changesetin the project root)Future Work
Related Issues