Skip to content

fix(prompt): update OpenAI JSON schema generation for serialization of nullable collections#1943

Merged
Andrey Bragin (EugeneTheDev) merged 1 commit into
JetBrains:developfrom
grantlerduck:fix/openai-serialization
May 28, 2026
Merged

fix(prompt): update OpenAI JSON schema generation for serialization of nullable collections#1943
Andrey Bragin (EugeneTheDev) merged 1 commit into
JetBrains:developfrom
grantlerduck:fix/openai-serialization

Conversation

@grantlerduck

Copy link
Copy Markdown
Contributor

Summary

  • Nullable List<X>? fields produced {"type": ["array", "null"], "items": {...}}, which OpenAI's
    GPT-5-family strict-mode validator rejects (surfaces as 'Invalid schema for response_format ... got "type": "None"'). Switch OpenAIStandardJsonSchemaGenerator.processList to emit
    {"anyOf": [{"type": "array", "items": ...}, {"type": "null"}]} for nullable lists, mirroring
    the shape already used for nullable objects.
  • Non-nullable lists, nullable primitives, and the LLM-agnostic StandardJsonSchemaGenerator are
    unchanged. Only the OpenAI-specific generator is touched, so other providers keep their existing
    type-union encoding.
  • Adds a regression test (testGenerateOpenAIStandardJsonSchemaForNullableLists) covering both
    primitive (List<String>?) and $ref (List<Tag>?) item types.

Out of scope (could follow up)

  • OpenAIBasicJsonSchemaGenerator still emits the OpenAPI-3.0-style nullable: true keyword, which
    OpenAI strict mode silently ignores. Same root cause family, different generator — happy to file
    a follow-up if useful.

closes #1930

@grantlerduck
grantlerduck force-pushed the fix/openai-serialization branch from ba54077 to 7ee683e Compare May 9, 2026 07:43
@grantlerduck

Copy link
Copy Markdown
Contributor Author

Just rebased. There was an agent run test which ran into a deadlock unrelated to my changes.

@EugeneTheDev Andrey Bragin (EugeneTheDev) changed the title fix(prompt): update OpenAI JSON schema generation for serialization o… fix(prompt): update OpenAI JSON schema generation for serialization of nullable collections May 26, 2026
@EugeneTheDev
Andrey Bragin (EugeneTheDev) merged commit 54b8ecb into JetBrains:develop May 28, 2026
36 of 41 checks passed
Andrey Bragin (EugeneTheDev) pushed a commit that referenced this pull request Jun 15, 2026
…f nullable collections (#1943)

## Summary

- Nullable `List<X>?` fields produced `{"type": ["array", "null"],
"items": {...}}`, which OpenAI's
GPT-5-family strict-mode validator rejects (surfaces as `'Invalid schema
for response_format ...
got "type": "None"'`). Switch
`OpenAIStandardJsonSchemaGenerator.processList` to emit
`{"anyOf": [{"type": "array", "items": ...}, {"type": "null"}]}` for
nullable lists, mirroring
the shape already used for nullable objects.
- Non-nullable lists, nullable primitives, and the LLM-agnostic
`StandardJsonSchemaGenerator` are
unchanged. Only the OpenAI-specific generator is touched, so other
providers keep their existing
type-union encoding.
- Adds a regression test
(`testGenerateOpenAIStandardJsonSchemaForNullableLists`) covering both
    primitive (`List<String>?`) and `$ref` (`List<Tag>?`) item types.

## Out of scope (could follow up)

- `OpenAIBasicJsonSchemaGenerator` still emits the OpenAPI-3.0-style
`nullable: true` keyword, which
OpenAI strict mode silently ignores. Same root cause family, different
generator — happy to file
a follow-up if useful.
closes #1930

(cherry picked from commit 54b8ecb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants