Skip to content

OpenAI strict mode rejects optional properties in nested objects #327

Open

Description

@mattt

OpenAILanguageModel and OpenResponsesLanguageModel send structured output schemas with strict: true. OpenAI's strict mode requires every property of every object to be in required, with a null type for an optional one. toJSONValueForOpenAIStrictMode() and toJSONValueForOpenResponsesStrictMode() only do this for the root object, so an optional property in a nested object is left out of required.

For example, unit isn't in Address's required here:

@Generable
struct Contact {
    var name: String
    var address: Address
}

@Generable
struct Address {
    var street: String
    var unit: String?
}

The same goes for enum cases with optional values, like case note(String?) (#322).

The fix is probably to apply the root's rules to every object in the schema, and make each optional property's type nullable.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions