Skip to content

Bug: OpenAI gpt-5+ model family JSON schema issues #1930

@grantlerduck

Description

@grantlerduck

When using nullable collections in the serializable data classes fro Structured output OpenAIs schema validation fails with 400 response:

Error from client: OpenAILLMClient                                                                                                                               
      Status code: 400                                                                                                                                                 
      Error body:                                                                                                                                                      
      {                                                                                                                                                                
        "error": {                                                                                                                                                     
          "message": "Invalid schema for response_format 'MyClass': schema must be a JSON Schema of 'type: \"object\"', got 'type: \"None\"'.", 
          "type": "invalid_request_error",                                                                                                                             
          "param": "response_format",                                                                                                                                  
          "code": null                                                                                                                                                 
        }                                                                                                                                                              
      }

Nullable list handling for List?: processList(...).asNullableType(...) produces {"type": ["array", "null"], "items": {...}}. Some OpenAI strict validators
reject the array form and want either anyOf: [array, null] or a top-level union elsewhere — pick wrong shape and the validator can't classify the type.

Reproducible with Dan Balla (@serializable) data class with one String field and one List? = null field and structured completion with any GPT 5 family model.

I am happy to contribute and can open a MR in the next days unless someone else already filed this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions