Skip to content

implement union type support for streaming actions#813

Open
ThyTran1402 wants to merge 2 commits into
apache:mainfrom
ThyTran1402:fix/stream_type_support_union_type
Open

implement union type support for streaming actions#813
ThyTran1402 wants to merge 2 commits into
apache:mainfrom
ThyTran1402:fix/stream_type_support_union_type

Conversation

@ThyTran1402

@ThyTran1402 ThyTran1402 commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Extends the @streaming_action.pydantic() decorator to accept union types like Model1 | Model2 or Union[Model1, Model2]) for the stream_type parameter. Previously, only single BaseModel types or dict were accepted, limiting flexibility for streaming actions that yield multiple result types.

Changes

  • burr/core/action.py
  • burr/integrations/pydantic.py
  • tests/integrations/test_streaming_union_types.py

How I tested this

Unit Tests: Created comprehensive test suite with 10 tests that all pass

Notes

Resolved: #607

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

@github-actions github-actions Bot added area/core Application, State, Graph, Actions area/integrations External integrations (LLMs, frameworks) area/typing Mypy, type hints, pydantic labels Jun 20, 2026
@ThyTran1402 ThyTran1402 changed the title phase III: implement union type support for streaming actions implement union type support for streaming actions Jun 20, 2026
@Ghraven

Ghraven commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for picking this up and for writing out the investigation so clearly.

One small thought from my earlier pass on this issue: adding object to the union does make the type checker accept union values, but it also effectively widens stream_type to almost any value. That may still be the pragmatic choice here, but maintainers may prefer either a more explicit alias/comment around why the parameter is intentionally broad, or a small runtime/type-helper path that recognizes union forms while keeping the public intent narrow.

The focused tests for both yping.Union[...] and ModelA | ModelB look useful. Thanks again for moving this forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Application, State, Graph, Actions area/integrations External integrations (LLMs, frameworks) area/typing Mypy, type hints, pydantic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming Event type, type hint, should support union type

2 participants