Repository navigation
feat(py): support list[T], TypedDict, and @dataclass in output_schema - #45
Open
huangjeff5 wants to merge 6 commits into
Open
huangjeff5 wants to merge 6 commits into
huangjeff5 wants to merge 6 commits into
Conversation
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 9, 2026 19:08
291e086 to
c93be6c
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 9, 2026 19:49
c93be6c to
5a290b5
Compare
huangjeff5
changed the base branch from
main
to
fix/py-1.0-pr1-docs-quickstart
November 9, 2026 19:49
huangjeff5
force-pushed
the
fix/py-1.0-pr1-docs-quickstart
branch
from
November 9, 2026 19:59
5ee7a6e to
c0ce853
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
2 times, most recently
from
November 9, 2026 20:19
db96b31 to
c831aef
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr1-docs-quickstart
branch
from
November 9, 2026 21:24
c0ce853 to
9df2ab7
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
2 times, most recently
from
November 9, 2026 22:03
24f0bae to
af2b347
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr1-docs-quickstart
branch
2 times, most recently
from
November 9, 2026 23:12
aa37fb2 to
4ac9ef3
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 9, 2026 23:12
af2b347 to
2148558
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr1-docs-quickstart
branch
from
November 10, 2026 07:44
4ac9ef3 to
65453be
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 10, 2026 07:44
2148558 to
1ea19dc
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr1-docs-quickstart
branch
from
November 10, 2026 18:14
65453be to
9f7cb68
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 10, 2026 18:14
1ea19dc to
7edc1a1
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr1-docs-quickstart
branch
from
November 10, 2026 21:50
d3c6672 to
8854224
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 10, 2026 21:51
7edc1a1 to
a5eb59e
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr1-docs-quickstart
branch
2 times, most recently
from
November 10, 2026 22:05
d3c6672 to
8854224
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 10, 2026 22:16
a5eb59e to
75288da
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
2 times, most recently
from
November 11, 2026 02:35
4d82180 to
33b6a5a
Compare
huangjeff5
changed the base branch from
fix/py-1.0-pr1-docs-quickstart
to
main
November 11, 2026 06:22
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 11, 2026 06:22
33b6a5a to
278fc9b
Compare
`ai.generate(output_schema=T)` types `.output` as `T`, but runtime only validated `BaseModel` subclasses. `list[T]`, `Literal`, and `Annotated` raised `ValidationError` on `GenerateCall`; dataclasses, `TypedDict`, `Enum`, `UUID`, `datetime`, and `Decimal` came back as raw JSON. - Drop the `BaseModel`-only gates in `GenerateCall.output_schema`, `Prompt._ensure_resolved`, and `resolve_output_schema`. Any non-dict, non-str schema becomes `schema_type`. - `ModelResponse.output` and `_assert_valid_schema` validate with a cached `TypeAdapter(schema_type)`. - `ModelResponseChunk.output` hydrates through `hydrate_partial`: open JSON is built leniently (lists of models, `RootModel`), closed JSON is validated like the final response. - `construct_partial(closed=True)` raises instead of falling back to `model_construct`, so the closing chunk never carries an object that skipped validators. Nested closed subtrees mid-stream keep the lenient fallback (`build_partial`). - Migration guide note for the three workarounds this breaks. Items: PR2-02, PR2-03, PR2-04 (D2).
Pins the shapes most likely to regress: InvoiceItem | None, a union of models picking the matching member, a dataclass nesting a dataclass, and a stream of a model that nests a dataclass and a TypedDict (open chunk keeps the TypedDict raw, closing chunk matches the final output).
…igration guide The guide covers 0.12 -> 0.13. The 1.0 note goes to the release notes.
…and invalid schemas
huangjeff5
force-pushed
the
fix/py-1.0-pr2-output-hydration
branch
from
November 11, 2026 18:38
278fc9b to
94b4a28
Compare
huangjeff5
added a commit
that referenced
this pull request
Nov 11, 2026
# Conflicts: # packages/genkit/src/genkit/_core/_model.py
This branch has not been 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.
Adds
output_schemasupport for non-BaseModelPython types backed by Pydantic'sTypeAdapter:list[T], stdlib@dataclass,TypedDict,RootModel,Enum,Literal,Annotated,Decimal,UUID, anddatetime.Previously, only Pydantic
BaseModelsubclasses (and raw JSON Schemadicts) were supported—passinglist[LineItem]crashed withValidationError,TypedDictskipped validation, and stdlib@dataclassreturned an unvalidateddictinstead of constructing the dataclass (BaseModelbehavior is unchanged).Main Changes
output_schemavalidates throughTypeAdapter:GenerateCall.output_schemawas typedtype, which rejected generic aliases likelist[LineItem]orVendor | None, andModelResponseonly called.model_validate()onBaseModelsubclasses. Validation now goes through a cachedTypeAdapter, so runtime.outputmatches the staticOutputT. Types Pydantic cannot build a schema for raiseInvalidOutputSchemaError(non-retryable).ModelResponseChunk.outputbuilt the last chunk withmodel_construct, skipping validation. The chunk that closes the JSON now runs full validation and isNoneif validation fails, matching(await stream.response).output.arrayandjsonlformats validate each emitted item.TypedDicts, and enums stay safe mid-stream: Open dataclasses andTypedDicts remain raw dicts until their JSON closes, and an enum chunk that is a prefix of multiple members staysNoneuntil disambiguated.type[OutputT]: Widening toAnywould lose.outputtype inference for every caller.Literal,Annotated, and union schemas work at runtime; static inference for non-typeforms waits on PEP 747TypeForm.Decisions
BaseModeland JSON Schemadictforoutput_schema(BaseModelbehavior is unchanged). Passing an unsupported@dataclasspreviously happened not to throw and returned a rawdict; constructing the@dataclassinstance brings runtime behavior in line with the declaredModelResponse[OutputT]type.Breaking changes
None.