Repository navigation
Python: add typing.Literal support to KernelJsonSchemaBuilder - #14514
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoOct 26, 2026
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
Conversation
PRABHU KIRAN VANDRANKI (VANDRANKI)
requested a review
from a team
as a code owner
September 30, 2026 16:41
PRABHU KIRAN VANDRANKI (VANDRANKI)
temporarily deployed
to
github-app-auth
September 30, 2026 16:41 — with
GitHub Actions
Inactive
PRABHU KIRAN VANDRANKI (VANDRANKI)
temporarily deployed
to
github-app-auth
September 30, 2026 16:41 — with
GitHub Actions
Inactive
Copilot stopped reviewing on behalf of
PRABHU KIRAN VANDRANKI (VANDRANKI) due to an error
September 30, 2026 16:42
Eduard van Valkenburg (eavanvalkenburg)
enabled auto-merge
October 26, 2026 13:54
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Oct 26, 2026
This branch was previously deployed
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.
Motivation and Context
KernelJsonSchemaBuilderhad no handling fortyping.Literal. A parameter typedLiteral["fast", "slow"]was advertised to the model as a bare{"type": "object"}with noenum, so the model was never told the allowed values. This also hit Pydantic fields,Optional[Literal[...]]andlist[Literal[...]].Fixes #14511
Description
In
handle_complex_type, aLiteralnow builds{"type": ..., "enum": [...]}, the same shapebuild_enum_schemareturns forEnumclasses:typeis the JSON type of the values when they all share one, otherwise a list of the types (with"null"last).Nonemaps to"null".Enummembers inside aLiteralare converted to their.value.Optional[Literal[...]](andLiteral[...] | None) now adds"null"totypeandNonetoenum. The Optional branch also no longer nests a list insidetypewhen the inner schema already has a list type.list[Literal[...]]works through the existinglistbranch and puts theenumonitems.Tests added in
tests/unit/schema/test_schema_builder.pycover str, int, bool, mixed, Optional,| None, list, Enum members, descriptions, and a Pydantic model with Literal fields. The new tests fail on current main and pass now.tests/unit/schema,tests/unit/functions,tests/unit/connectors/utilsandtest_function_choice_behavior.py: all pass.ruffandmypyare clean on the changed files. The repro from the issue now gives{"type": "string", "enum": ["fast", "slow"], "description": "speed mode"}formodeand anenumon the nestedlevelfield.Contribution Checklist