Skip to content

[Python] Add typed decision questions and model adapters - #40220

Open
bvolpato wants to merge 8 commits into
apache:masterfrom
bvolpato:bvolpato/decision-model-jev-poc
Open

bvolpato wants to merge 8 commits into
apache:masterfrom
bvolpato:bvolpato/decision-model-jev-poc

Conversation

@bvolpato

@bvolpato bvolpato commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds typed Choice, Boolean, and Score questions to Beam Python. EvaluateDecisions applies a DecisionModel adapter to each input element, so pipelines can change adapters while keeping their questions and downstream policy.

The transform reuses the adapter context across elements and bundles on each worker DoFn instance. Results retain the original input, timestamps, and windows, with model/provider identifiers and request latency. The transform records request metrics and closes the context during best-effort teardown.

The optional Jev adapter maps Boolean questions to Noul and validates responses. The fraud example's optional JSONL error output catches malformed-response validation failures. Setup errors and exhausted transport failures still fail that pipeline. Calls and retries block the processing thread, and the transform does not coordinate a global request-rate limit.

The README covers installation, local demos, and cloud options.

Local mocked validation and the routing and fraud demos passed. Python 3.12 ML CI passed with the optional SDK installed for the adapter tests. Provider calls were not repeated for the response-validation changes, and the routing example's BigQuery sink has not been tested against the live service.

Run the ML unit suite with:

./gradlew :sdks:python:test-suites:tox:py312:testPy312ML

  • If this contribution is large, please file an Apache Individual Contributor License Agreement.
  • Replace these instructions with a description of your change and why you have made it.
  • Mention the appropriate issue in your description (for example: addresses #123 or fixes #456).
  • Update CHANGES.md with noteworthy changes.

See CONTRIBUTING.md for contribution guidelines.

@bvolpato
bvolpato force-pushed the bvolpato/decision-model-jev-poc branch 2 times, most recently from 6679bdf to 218da73 Compare September 22, 2026 17:17
@bvolpato bvolpato changed the title [Python] Add decision model routing examples [Python] Add reusable decision model primitives Sep 22, 2026
@bvolpato
bvolpato force-pushed the bvolpato/decision-model-jev-poc branch from 218da73 to 81a3c48 Compare September 22, 2026 23:16
@bvolpato
bvolpato marked this pull request as ready for review September 23, 2026 04:09
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@bvolpato

Copy link
Copy Markdown
Contributor Author

Run PythonDocs PreCommit

@jrmccluskey jrmccluskey 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.

This is a neat framework! Just a few documentation nits and a question around the potential for malformed responses

Comment thread sdks/python/apache_beam/ml/inference/typesafe_inference.py Outdated
Comment thread sdks/python/apache_beam/ml/inference/typesafe_inference.py Outdated
Comment thread sdks/python/apache_beam/examples/inference/decision_models/README.md Outdated
Comment thread sdks/python/apache_beam/examples/inference/decision_models/README.md Outdated
Comment thread sdks/python/apache_beam/ml/inference/typesafe_inference.py
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.47059% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.36%. Comparing base (76f6e6d) to head (5655d4a).
⚠️ Report is 179 commits behind head on master.

Files with missing lines Patch % Lines
...hon/apache_beam/ml/inference/typesafe_inference.py 25.33% 56 Missing ⚠️
sdks/python/apache_beam/ml/inference/decision.py 98.94% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #40220      +/-   ##
============================================
+ Coverage     56.16%   56.36%   +0.19%     
  Complexity     2288     2288              
============================================
  Files          1124     1127       +3     
  Lines        178336   178650     +314     
  Branches       1489     1488       -1     
============================================
+ Hits         100170   100691     +521     
+ Misses        75645    75435     -210     
- Partials       2521     2524       +3     
Flag Coverage Δ
python 79.87% <66.47%> (+0.32%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bvolpato bvolpato changed the title [Python] Add reusable decision model primitives [Python] Add typed decision questions and model adapters Oct 13, 2026
Comment thread sdks/python/tox.ini Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants