fix(ai): use errorMode 'text' in approval continuation to preserve tool error messages#13056
Merged
aayush-kapoor merged 2 commits intovercel:mainfrom Mar 4, 2026
Merged
fix(ai): use errorMode 'text' in approval continuation to preserve tool error messages#13056aayush-kapoor merged 2 commits intovercel:mainfrom
aayush-kapoor merged 2 commits intovercel:mainfrom
Conversation
…ion flow
When a tool with needsApproval throws an error during execution, the error
message was silently lost. The approval continuation path in both streamText
and generateText used errorMode: 'text' ? 'json' : 'none' (bug: 'json'
should be 'text'). JSON.stringify(new Error('msg')) returns '{}' because
Error properties are non-enumerable, so the model received '{}' instead of
the actual error message.
The fix aligns the approval continuation path with the normal multi-step
flow and to-response-messages.ts which correctly use errorMode: 'text',
causing getErrorMessage() to extract the message string.
Fixes vercel#13048
haroldfabla2-hue
pushed a commit
to haroldfabla2-hue/ai
that referenced
this pull request
Mar 4, 2026
When a tool with needsApproval throws an error during execution, the error
message was being lost because errorMode 'json' routes to createToolModelOutput
which does JSON.stringify(new Error('msg')) resulting in '{}' since Error
properties are non-enumerable.
This fix changes 'json' to 'text' in both generateText and streamText to
align with the normal multi-step flow that correctly uses getErrorMessage.
Closes vercel#13056
aayush-kapoor
approved these changes
Mar 4, 2026
Collaborator
aayush-kapoor
left a comment
There was a problem hiding this comment.
just made some minor test fixes + added changeset
Contributor
Author
|
@aayush-kapoor thank you! :) yeah.. changeset this is painfull for me hahah. everytime forgot it.. |
Contributor
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.
Problem
When a tool with
needsApprovalthrows an error during execution, the error message is silently lost. The model receives{}instead of the actual error text, causing it to hallucinate success.Closes #13048
Root Cause
The approval continuation path in both
streamTextandgenerateTextused:errorMode: 'json'routes tocreateToolModelOutputwhich doestoJSONValue(error)→JSON.stringify(new Error('msg'))→'{}'becauseErrorproperties (message,stack) are non-enumerable.The normal multi-step flow and
to-response-messages.tscorrectly useerrorMode: 'text'which callsgetErrorMessage(error)to extract the message string.Fix
Change
'json'→'text'in both locations to align with the normal flow:Tests
Added test cases for both
generateTextandstreamTextthat verify when an approvedneedsApprovaltool throws, the model receives{ type: 'error-text', value: 'tool execution failed' }instead of{ type: 'error-json', value: {} }.