Skip to content

Normalize undefined/missing tool call outputs to null - #16387

Open
nwalters512 wants to merge 8 commits into
vercel:mainfrom
nwalters512:normalize-missing-tool-call-outputs
Open

Normalize undefined/missing tool call outputs to null#16387
nwalters512 wants to merge 8 commits into
vercel:mainfrom
nwalters512:normalize-missing-tool-call-outputs

Conversation

@nwalters512

Copy link
Copy Markdown
Contributor

Background

#15855 updated toUIMessageChunk(...) to coerce missing or undefined tool output to null so that it survives being round-tripped through JSON. However, applications that persisted such data before that fix was in place will have persisted data where output is missing, so attempting to load or validate it would fail.

Summary

This PR updates the conversion and validation paths to accept missing data and coerce it to null. This allows applications that wrote data before #15855 landed to continue working without local intervention.

Manual Verification

I tested the changes in my app with data matching what would have been written before #15855 landed. Without the changes on this branch, I saw Zod validation errors. With these changes, everything works.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • 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

N/A

Related Issues

#15854 describes the root issue here.

Comment on lines +468 to +471
formatRawChunk({
type: 'tool-output-available',
toolCallId: 'call-1',
}),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatRawChunk is used because formatChunk expects a UIMessageChunk, but this deliberately deviates from that shape.

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