fix(openai-compatible,provider-utils): JSON schema validation#13217
Open
dixoxib wants to merge 3 commits intovercel:mainfrom
Open
fix(openai-compatible,provider-utils): JSON schema validation#13217dixoxib wants to merge 3 commits intovercel:mainfrom
dixoxib wants to merge 3 commits intovercel:mainfrom
Conversation
packages/openai-compatible/src/chat/openai-compatible-prepare-tools.ts
Outdated
Show resolved
Hide resolved
75a8403 to
c8fd011
Compare
c8fd011 to
8692580
Compare
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
OpenAI-compatible providers with strict JSON schema validation (like DeepSeek) reject all tool calls with the error:
Invalid schema for function: schema must be a JSON Schema of 'type: "object"', got 'type: null'.This issue (#7924) affects all OpenAI-compatible providers when tools have no explicit
inputSchemaor whenasSchema()creates empty schemas without the requiredtype: "object"field.Summary
Fixed JSON schema validation by:
@ai-sdk/provider-utils: Added missingtype: 'object'to empty JSON schemas inasSchema()function@ai-sdk/openai-compatible: MadeprepareTools()async and addedjsonSchema()fallback for undefinedinputSchema@ai-sdk/alibaba: AddedawaittoprepareTools()call (required now that it's async)These changes ensure that all generated JSON schemas are valid according to JSON Schema Draft 7 specification, which requires the
typefield.Manual Verification
Verified with real DeepSeek API requests:
"type: null"schema validation errors{type: 'object', properties: {}, additionalProperties: false}schemasprepareTools()Test commands executed: