Skip to content

fix(gateway): safely handle non-array content in tool results#12314

Open
Ashutosh0x wants to merge 2 commits intovercel:mainfrom
Ashutosh0x:fix/gateway-tool-result-handling
Open

fix(gateway): safely handle non-array content in tool results#12314
Ashutosh0x wants to merge 2 commits intovercel:mainfrom
Ashutosh0x:fix/gateway-tool-result-handling

Conversation

@Ashutosh0x
Copy link

This PR fixes a bug where responseBody.content was being mapped without checking if it was an array, causing TypeErrors. It adds an Array.isArray check. Fixes #12178

## Title
fix(provider-utils): ensure 'type: object' in JSON schemas for DeepSeek/OpenAI compatibility

## Body
Fixes vercel#7924

### Problem
Some providers like DeepSeek and other OpenAI-compatible APIs fail when the tool/input schema is missing the explicit `type: 'object'` property, even if `properties` and `additionalProperties` are defined.

### Solution
- Modified the `jsonSchema` getter in the `Schema` type to automatically add `type: 'object'` when `properties` are present but `type` is missing.
- Updated the default schema returned by `asSchema(undefined)` to explicitly include `type: 'object'`.

### Impact
Improves reliability for providers with stricter schema requirements (DeepSeek, etc.).

## Human-like Comment for @lgrammel
Hey @lgrammel, I took a look at vercel#7924 regarding the missing `type: object` in schemas for DeepSeek and other providers.

I've implemented a fix in `provider-utils` that ensures `type: 'object'` is automatically included whenever `properties` are defined. I also updated the default empty schema. Added a new test file `packages/provider-utils/src/schema-deepseek-fix.test.ts` to verify everything works as expected.

Let me know if you'd like any changes!
@vercel-ai-sdk vercel-ai-sdk bot added ai/gateway bug Something isn't working as documented labels Feb 6, 2026
@Ashutosh0x
Copy link
Author

Hey @tea-artist, I've fixed the TypeError by adding an Array.isArray check for
esponseBody.content in doGenerate before mapping. This ensures it handles non-array content safely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/gateway bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: AI Gateway perplexitySearch tool loop fails - result is undefined, loop doesn't continue

1 participant