Feature: opt-in per-constant descriptions for enum in JacksonOutputConverter - #2072
Open
sumitvairagar wants to merge 1 commit into
Open
sumitvairagar wants to merge 1 commit into
sumitvairagar wants to merge 1 commit into
Conversation
When JacksonOutputConverterOption.ENUM_CONSTANT_DESCRIPTIONS is passed,
enum constants annotated with @JsonPropertyDescription are emitted as
oneOf [ { const, description }, ... ] instead of a bare enum array,
so the model receives the prose written for each option.
The option is opt-in because oneOf is not supported by OpenAI native
structured-output strict mode and would cause schema fallback to the
prompt-based path on that provider. Enums with no annotated constants
are unaffected regardless of the option.
Closes embabel#2028
igordayen
self-requested a review
September 26, 2026 16:10
Contributor
|
@sumitvairagar - thanks for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2028
What
Adds
JacksonOutputConverterOption.ENUM_CONSTANT_DESCRIPTIONS— an opt-in flag that installs aCustomDefinitionProviderV2to emit per-constant@JsonPropertyDescriptionannotations asoneOf/const/descriptioninstead of a bareenumarray.For an enum like:
the schema becomes:
{ "oneOf": [ { "const": "URGENT", "description": "Needs same-day response" }, { "const": "NORMAL", "description": "Standard turnaround" }, { "const": "OTHER" } ]}Why opt-in
As discussed in #2028,
oneOfis not supported by OpenAI native structured-output strict mode and causes schema fallback to the prompt-based path on that provider. The opt-in flag makes this a conscious choice — consumers on Google GenAI, Anthropic, or the prompt-based path can enable it; the default path stays unchanged and OpenAI strict mode is unaffected.Enums whose constants carry no
@JsonPropertyDescriptionare unaffected regardless of the option.Tests
Four new tests in
EnumConstantDescriptionTests:enumarray (unchanged behaviour)oneOf/const/descriptionList<>\ also becomesoneOf`enumAll 55 tests pass.