fix(bedrock): raise_for_status in WrappedBotoClient so gateway errors surface#95
Merged
Merged
Conversation
… surface WrappedBotoClient read responses with .json()/iter_bytes without checking the HTTP status, so a non-2xx gateway response (e.g. 403 License-not-available) was parsed as a normal result and handed to langchain_aws, which then raised a misleading "No 'output' key ... misconfiguration of endpoint or region" ValueError - losing the real status code and detail. Call raise_for_status() in converse, invoke_model, and the streaming generator so gateway HTTP errors surface as the patched UiPathAPIError subclass (e.g. UiPathPermissionDeniedError), matching the OpenAI and Vertex paths. For streaming, read the error body first so the typed exception keeps its detail. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ionut-mihalache-uipath
approved these changes
Jun 23, 2026
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.
Problem
WrappedBotoClient(the httpx-backed Bedrock shim that replaces boto3 when talking to the LLM Gateway) read responses with.json()/iter_bytes()without checking the HTTP status. On a non-2xx gateway response — e.g. a403 License not available— the error body was parsed as if it were a normal Converse result and handed tolangchain_aws, which then raised a misleading:The real status code (403) and the gateway's
detail("…you need additional 'AGU'") were lost — so a licensing error surfaced as a confusing "check your endpoint/region" message.Fix
Call
response.raise_for_status()before reading the body inconverse,invoke_model, and the streaming generator (_stream_generator, used byconverse_stream/invoke_model_with_response_stream). The UiPath httpx client's patchedraise_for_statusthen raises the typedUiPathAPIErrorsubclass (e.g.UiPathPermissionDeniedError, carrying.status_codeand.body).For streaming responses the error body is read first (
if response.is_error: response.read()), since the gateway returns a non-streamed JSON error body andUiPathAPIError.from_responseparsesresponse.json()to populatedetail. Verified on httpx 0.28.1 thatis_error/status_codeare available from the response headers inside thestream()context before the body is read, and that the success path still streams viaiter_bytes().Verification
Confirmed end-to-end against a real gateway 403: the Bedrock Converse path now produces
UiPathPermissionDeniedError(status_code=403, body={... "detail": "License not available ... 'AGU'" ...})instead of the opaqueValueError.Tests
New
tests/langchain/clients/bedrock/test_wrapped_boto_client.py:converse/invoke_modelraise on a 403 (andconversereturns the body on 200)converse_stream/invoke_model_with_response_streamraise on a 403 when consumed🤖 Generated with Claude Code