[PR #8218] fix(provider): add required field to object schemas for strict validators #12668

Open
opened 2026-02-16 18:17:34 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8218

State: open
Merged: No


Summary

Fixes #8184

Backends like SGLang with strict JSON Schema validation (using Pydantic) fail when object schemas don't have a required field, returning errors like:

Tool function has invalid 'parameters' schema: None is not of type 'array' on schema['required']

This PR ensures all object-type schemas have required set (as an empty array [] if no fields are required).

Changes

  • Added ensureRequiredField() helper in ProviderTransform.schema() that recursively adds required: [] to all object schemas that don't have it
  • Added comprehensive tests covering empty objects, nested objects, deeply nested objects, arrays of objects, and preservation of existing required fields

Test plan

  • All existing tests pass
  • New tests verify the fix works for various schema structures
  • Manual testing with SGLang backend (would need access to such a backend)

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8218 **State:** open **Merged:** No --- ## Summary Fixes #8184 Backends like SGLang with strict JSON Schema validation (using Pydantic) fail when object schemas don't have a `required` field, returning errors like: ``` Tool function has invalid 'parameters' schema: None is not of type 'array' on schema['required'] ``` This PR ensures all object-type schemas have `required` set (as an empty array `[]` if no fields are required). ## Changes - Added `ensureRequiredField()` helper in `ProviderTransform.schema()` that recursively adds `required: []` to all object schemas that don't have it - Added comprehensive tests covering empty objects, nested objects, deeply nested objects, arrays of objects, and preservation of existing required fields ## Test plan - [x] All existing tests pass - [x] New tests verify the fix works for various schema structures - [ ] Manual testing with SGLang backend (would need access to such a backend) --- 🤖 Generated with [Claude Code](https://claude.com/claude-code)
yindo added the pull-request label 2026-02-16 18:17:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12668