Skip to content

Feature: native structured output refinements — strict mode, schema fixes - #2027

Open
igordayen wants to merge 1 commit into
mainfrom
native-structured-output-refinements
Open

igordayen wants to merge 1 commit into
mainfrom
native-structured-output-refinements

Conversation

@igordayen

@igordayen igordayen commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

See issue: #1966

  • Strict mode: OpenAiNativeStructuredOutputConfigurer now calls .strict(true) on the OpenAI response format, enforcing the schema contract at the API level
  • Schema fix: schemaType() in jsonSchemaSupport correctly handles array nodes
  • Nullable union: `supports Java Optional
  • Docs: NativeStructuredOutputMode KDoc clarifies that DISABLED opts out entirely
    DEFAULT policy description tightened

Java — Optional field example

class PersonWithAge {
    @JsonProperty(required = true)
    public String name;
    @JsonProperty(required = true)
    public int age;
    @JsonProperty(required = true)
    public Optional<String> nickname;  // maps to {"type":["string","null"]} in JSON Schema
}

Optional and Kotlin T? are both supported in DEFAULT and ENABLED modes. The field is included in required[] with a
["type","null"] union — OpenAI strict mode accepts this.

Known limitations (DEFAULT mode)

  • Enums — not supported; fall back to prompt-based extraction
  • Map<K,V> — not supported (produces additionalProperties, rejected by the compatibility check)
  • Nested arrays of arrays — not supported (2D arrays fall through to else -> false)
  • $ref, oneOf, anyOf, allOf, not — any schema using these keywords is rejected; affects sealed classes, polymorphic types, and Jackson subtypes
  • Optional<Array/List> — nullable arrays not supported in the union check (else -> false in isValidNullableUnion)
  • ENABLED mode bypasses all of the above — no compatibility check, schema is sent as-is; the provider may reject it

Testing

  • NativeStructuredOutputSupportTest — nullable union and array compatibility
  • OpenAiNativeStructuredOutputConfigurerTest — strict mode assertion
  • jsonSchemaSupportTest — schema type correctness
  • OpenAiNativeStructuredOutputIT — live OpenAI (requires OPENAI_API_KEY)

…ixes

  - Enable OpenAI strict mode in OpenAiNativeStructuredOutputConfigurer
  - Fix schemaType() for array nodes in jsonSchemaSupport; support Optional
@sonarqubecloud

Copy link
Copy Markdown

@igordayen

Copy link
Copy Markdown
Contributor Author

@stefanks-px - could you please validate, thank you

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.

1 participant