fix(decisioning): wrap pydantic.ValidationError from delegates as INVALID_REQUEST#656
Merged
bokelley merged 3 commits intoMay 11, 2026
Merged
Conversation
…ALID_REQUEST Closes #652 Platform methods that manually call `RequestModel.model_validate()` with a buyer's payload against a stricter subclass schema now surface as `INVALID_REQUEST` (correctable) with field paths populated from the validation error, instead of the previous `INTERNAL_ERROR` (terminal) that stripped all field information from the wire envelope. The fix adds an `except pydantic.ValidationError` clause in `_invoke_platform_method` between the existing `except TypeError` and `except Exception` handlers, matching the behaviour already present in `_coerce_params_to_platform_type` for the annotation-coercion path. A shared `_validation_error_to_invalid_request` helper builds the AdcpError with `narrow_union_errors`-filtered `details.validation_errors` so buyers get the same structured field list on both paths. https://claude.ai/code/session_01J7nYYToyy7PCs6CgQGRAWN
Pre-PR review blocker: the fallback exc.errors() call in _validation_error_to_invalid_request was missing include_input=False and include_context=False, which could expose buyer-supplied field values in details.validation_errors on the wire when narrow_union_errors is unavailable. https://claude.ai/code/session_01J7nYYToyy7PCs6CgQGRAWN
…_REQUEST Review feedback on PR #656. The nested try/except in _validation_error_to_invalid_request swallowed errors from narrow_union_errors() and a second call to exc.errors(), violating the repo's no-fallbacks policy. Both APIs are stable (in-repo + Pydantic public surface); a failure there is a real bug we want surfaced. Also tighten the `exc` parameter from `Any` to `ValidationError` via the existing TYPE_CHECKING import block — static type tools now flag misuse at the call site. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #652
Summary
Platform delegates that manually call
RequestModel.model_validate()against a stricter subclass schema previously surfaced asINTERNAL_ERROR (terminal)when the buyer's input failed validation, stripping all field information from the wire envelope. This PR converts thosepydantic.ValidationErrorexceptions toINVALID_REQUEST (correctable)with populatedfieldanddetails.validation_errors, matching the behaviour already present in_coerce_params_to_platform_typefor the annotation-coercion path.Two changes:
_validation_error_to_invalid_requesthelper — builds theAdcpError("INVALID_REQUEST")withnarrow_union_errors-filtered field paths, with a safe fallback if the narrowing import fails. Input values are excluded from the error payload on both paths (include_input=False) to avoid leaking buyer-supplied data.except _ValidationErrorclause in_invoke_platform_method— inserted betweenexcept TypeErrorandexcept Exception, fireson_failurehook (so proposal-flow reservations are released) before re-raising the wrapped error.Note: the framework cannot distinguish a buyer-request
ValidationErrorfrom a seller-response constructionValidationErrorat this catch boundary. The tradeoff is intentional and consistent with_coerce_params_to_platform_type— surfacingINVALID_REQUEST correctablewith field paths is strictly more informative thanINTERNAL_ERROR terminalin either case.What was tested
pytest tests/test_decisioning_dispatch.py→ 56 passed (includes updatedtest_invoke_validation_error_surfaces_narrowed_field_pathsand newtest_invoke_validation_error_from_manual_model_validate_is_invalid_request)pytest tests/ --ignore=tests/integration→ 4298 passed, 0 new failures (1 pre-existing TLS integration test excluded)ruff check src/adcp/decisioning/dispatch.py→ all checks passedmypy src/adcp/decisioning/dispatch.py --ignore-missing-imports→ no new errors on changed linesPre-PR review
exc.errors()call now passesinclude_input=False, include_context=Falseto prevent buyer-supplied data leaking intodetails.validation_errors; 1 nit noted (exc: Anysignature loses static type info)fielddot-join produces correct"extra_field"forextra='forbid'errors;detailsshape asymmetry from_internal_error_detailsis intentional; nosuggestionfield is consistent with all peerINVALID_REQUESTwraps in the same fileSession: https://claude.ai/code/session_01J7nYYToyy7PCs6CgQGRAWN
Generated by Claude Code