Repository navigation
fix(typesafe): reject empty questions in TypeSafeClassifier - #41241
Champions Zhang (ChampionsZhang) wants to merge 8 commits into
Conversation
Aayush Trada (codeitwithaayush)
left a comment
There was a problem hiding this comment.
Thanks for the PR! I inspected the changes and the added unit test.
The validation logic cleanly guards _payload by checking if not request["questions"]: and raising a ValueError, which correctly prevents empty requests from hitting the network layer. The added unit test covers both synchronous and asynchronous paths (invoke and ainvoke) using mock clients to ensure no HTTP requests are dispatched on invalid input.
Everything looks solid and well-tested. Good catch restoring this validation path!
Christopher Krah (chrikrah)
left a comment
There was a problem hiding this comment.
Champions Zhang (@ChampionsZhang) d1cb7e3 restores the empty-questions rejection. From my perspective this can be merged. #40706 already traces the lost Field(min_length=1) to #40659. I checked two things only: the new test catches it, and nothing reaches the HTTP client.
$ python -m pytest tests/unit_tests -q # libs/partners/typesafe at d1cb7e3, CPython 3.14.7
93 passed in 1.84s
$ python -m pytest tests/unit_tests -q # classifier.py from 8ace87e, everything else from d1cb7e3
2 failed, 91 passed, 2 warnings in 1.15s
FAILED tests/unit_tests/test_classifier.py::test_empty_questions_are_rejected_before_request[False]
FAILED tests/unit_tests/test_classifier.py::test_empty_questions_are_rejected_before_request[True]
$ python probe41241.py # invoke({"state": "hi", "questions": {}}) with a callback handler, at 16ccdd3 (d1cb7e3 only merges master)
raised: ValueError TypeSafe classifier requests must contain at least one question.
callbacks: ['chain_start', 'chain_error:ValueError'] | post called: False
Neither middleware hits the new error: AutoModeMiddleware.tools and ModelRouterMiddleware.choices keep Field(min_length=1).
non-blocking: on the open question in #40706, I'd keep the check in the shared request path. A bad call then shows up as a failed run.
Is anything still missing before this can merge?
|
Thanks for the thorough review and verification! Really appreciate it. |
Fixes #40706
Replaces #40707, which was automatically closed when my source fork was deleted. This PR restores the exact same branch and commits; the previous discussion and community review are available in #40707.
Direct
TypeSafeClassifiercallers can build an empty question mapping dynamically, but invocation-scopedClassifierRequestno longer enforces the formermin_length=1, so invalid requests reach the API. This restores local validation in the shared request-building path and covers both synchronous and asynchronous execution without calling either HTTP client.Release note
TypeSafeClassifiernow raises aValueErrorbefore sending requests whosequestionsmapping is empty.This contribution was developed with assistance from an AI coding agent and reviewed by me.