Skip to content

fix(py)!: a flow's input and output are checked - #6575

Merged
huangjeff5 merged 12 commits into
feat/py-request-data-fieldsfrom
fix/py-flow-io-validated
Oct 7, 2026
Merged

huangjeff5 merged 12 commits into
feat/py-request-data-fieldsfrom
fix/py-flow-io-validated

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

A flow's input and return are checked. Extra return keys follow the model's own extra= (default ignore). Receipt ignores tip_cents unless extra='forbid'.

@ai.flow()
async def bill() -> Receipt:
    return {'table': 4, 'tip_cents': 300}

# extra default (ignore): Receipt(table=4, note=None)
# extra='forbid':         INTERNAL / INVALID_OUTPUT, tip_cents: Extra inputs are not permitted

Decisions

  • Extra keys are dropped unless the model set extra='forbid' (run fails) or extra='allow' (kept).
  • Flask / Django: omitted optional fields come back as null (model_dump()).
  • FastAPI: explicit nulls are dropped and alias models use their alias (model_dump(by_alias=True, exclude_none=True)).
  • The Flask/Django vs FastAPI dump split is older than this PR and stays as-is for 1.0 (fix(py)!: a Message inside your own Pydantic model dumps the same as on its own #6559).
  • A matching dict becomes the model; the server sends that model the way it sends any model.
  • Hidden input values (hide_input_in_errors=True) are omitted from the short error text.
  • details.errors lists every ValidationError problem (loc / message / type, no input).
  • Apply fix(py): served flows send PublicError text; other GenkitError is 500 #6499 before this PR.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Genkit framework across Django, FastAPI, Flask, and core packages to correctly handle omitted inputs and explicit null values, ensuring that Python default arguments are applied when no input is provided. It introduces a NO_INPUT sentinel to distinguish between omitted inputs and explicit None values. Additionally, it adds validation for flow return values against their return annotations, raising an internal error with an INVALID_OUTPUT reason on mismatch. Comprehensive tests are added to verify these behaviors across all supported web frameworks. There are no review comments to address, and I have no additional feedback to provide.

@huangjeff5
huangjeff5 added this pull request to stack #6583 October 6, 2026 04:43
`await flow(x, context=...)` passes context on the plain call. An explicit
`await flow(None)` is validated against the input annotation instead of
being swapped for the Python default; `await flow()` still uses the
default. Over HTTP and from the Dev UI, a missing input and a null input
both still mean "no input".

A flow's return value is validated against its return annotation: a
matching dict comes back as the model, and a mismatch fails the run with
GenkitError(INTERNAL, reason INVALID_OUTPUT). Served flows answer that
with a plain 500.
@huangjeff5
huangjeff5 force-pushed the fix/py-flow-io-validated branch from c906165 to 6b7b1ca Compare October 6, 2026 06:37
@github-actions github-actions Bot added the docs Improvements or additions to documentation label Oct 6, 2026
@huangjeff5
huangjeff5 removed this pull request from stack #6583 October 6, 2026 06:38
@huangjeff5
huangjeff5 changed the base branch from fix/py-served-flow-errors to feat/py-request-data-fields October 6, 2026 06:38
@huangjeff5
huangjeff5 added this pull request to stack #6548 October 6, 2026 06:38
@huangjeff5
huangjeff5 marked this pull request as ready for review October 6, 2026 08:15
# Conflicts:
#	py/packages/genkit/src/genkit/_core/_action.py
…o fix/py-flow-io-validated

# Conflicts:
#	py/packages/genkit-django/src/genkit_django/handler.py
#	py/packages/genkit-django/tests/django_test.py
#	py/packages/genkit-fastapi/tests/fastapi_test.py
#	py/packages/genkit-flask/src/genkit_flask/handler.py
# Conflicts:
#	py/packages/genkit-django/tests/django_test.py
#	py/packages/genkit/src/genkit/_core/_action.py
@huangjeff5
huangjeff5 merged commit 2b1e061 into main Oct 7, 2026
39 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-flow-io-validated branch October 7, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation fix python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants