Skip to content

fix(openai-compatible,provider-utils): JSON schema validation#13217

Open
dixoxib wants to merge 3 commits intovercel:mainfrom
dixoxib:fix-json-schema-validation
Open

fix(openai-compatible,provider-utils): JSON schema validation#13217
dixoxib wants to merge 3 commits intovercel:mainfrom
dixoxib:fix-json-schema-validation

Conversation

@dixoxib
Copy link

@dixoxib dixoxib commented Mar 8, 2026

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 inputSchema or when asSchema() creates empty schemas without the required type: "object" field.

Summary

Fixed JSON schema validation by:

  1. @ai-sdk/provider-utils: Added missing type: 'object' to empty JSON schemas in asSchema() function
  2. @ai-sdk/openai-compatible: Made prepareTools() async and added jsonSchema() fallback for undefined inputSchema
  3. @ai-sdk/alibaba: Added await to prepareTools() 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 type field.

Manual Verification

Verified with real DeepSeek API requests:

  • Tool calling with DeepSeek no longer fails with "type: null" schema validation errors
  • Tools with explicit schemas continue to work correctly
  • Tools without explicit schemas now receive valid {type: 'object', properties: {}, additionalProperties: false} schemas
  • All existing OpenAI-compatible provider tests pass (177 tests)
  • Manual check for providers utilizing prepareTools()

Test commands executed:

# Build affected packages
cd packages/provider-utils && pnpm build
cd packages/openai-compatible && pnpm build

# Run tests
cd packages/openai-compatible && pnpm test  # All 177 tests pass

## Related Issues
Fixes #7924

@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/deepseek Issues related to the @ai-sdk/deepseek provider provider/openai-compatible labels Mar 8, 2026
@dixoxib dixoxib force-pushed the fix-json-schema-validation branch 2 times, most recently from 75a8403 to c8fd011 Compare March 8, 2026 18:54
@dixoxib dixoxib force-pushed the fix-json-schema-validation branch from c8fd011 to 8692580 Compare March 8, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/deepseek Issues related to the @ai-sdk/deepseek provider provider/openai-compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant