Skip to content

Conversation

@ipince
Copy link
Contributor

@ipince ipince commented Dec 2, 2025

Summary

OpenAI uses jsonschema to define a function tool's input (and other things), but they don't support any arbitrary json schema. Here we implement some (but not all) of the supported subset, and force that schemas always contain properties, even if empty. These were being omitted when empty because the Schema struct has json:"omitempty")

Implementing all the OpenAI restrictions seems like unnecessary eager validation. The API itself will return an error if an invalid schema is passed in.

How was it tested?

Unit tests

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.

By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.

@ipince ipince requested a review from loreto December 2, 2025 21:08
Copy link
Contributor

@loreto loreto left a comment

Choose a reason for hiding this comment

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

LGTM

// https://platform.openai.com/docs/guides/structured-outputs#root-objects-must-not-be-anyof-and-must-be-an-object
// NOTE: we could simply encode the input schema, pass it through to OpenAI and let it return an error, but there are
// other encoding rules we want to enforce later, and limiting the scope here allows us to limit the scope later.
if schema.Type != "object" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would create a helper validateSchema method. Up to you though.

@ipince ipince merged commit 7cdb063 into main Dec 2, 2025
13 checks passed
@ipince ipince deleted the rodrigo/aisdk-schema branch December 2, 2025 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants