Skip to content

fix(bedrock): let non-InvokeError exceptions propagate from _invoke inference-profile branch (#3653) - #3794

Closed
Taranum01 wants to merge 2 commits into
langgenius:mainfrom
Taranum01:fix/3653-bedrock-exception
Closed

Taranum01 wants to merge 2 commits into
langgenius:mainfrom
Taranum01:fix/3653-bedrock-exception

Conversation

@Taranum01

@Taranum01 Taranum01 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3653.

Problem

models/llm/llm.py _invoke (inference-profile branch, lines 240-243) wrapped the entire branch in a bare except Exception and re-raised as a generic InvokeError:

try:
    ...
except Exception as e:
    logger.error(f"Failed to invoke inference profile: {str(e)}")
    raise InvokeError(f"Failed to invoke inference profile {inference_profile_id}: {str(e)}")

A NameError, TypeError, KeyError, or any other non-InvokeError exception raised inside the try block (by _get_model_info, get_inference_profile_info, _generate_with_converse, or any of the dict accessors) surfaced as a generic InvokeError whose message contained the original exception string, hiding the root cause and traceback.

This is the same anti-pattern that PR #3565 (issue #3564) fixed in _generate, and PR #3661 (issue #3661) fixed in _generate_with_converse. The fix mirrors both.

Fix

except (ClientError, KeyError) as ex:
    # Specific AWS-boto3 client errors and any unexpected KeyError are
    # real bugs the operator should see — surface them as InvokeError
    # without hiding the message.
    logger.exception("Failed to invoke inference profile")
    raise InvokeError(f"Failed to invoke inference profile {inference_profile_id}: {str(ex)}")
except Exception as ex:
    # Unknown errors (NameError, TypeError, AttributeError, …) must
    # propagate verbatim so the operator sees the real traceback
    # instead of a misleading InvokeError.
    logger.exception("Unexpected error invoking inference profile")
    raise ex

Tests

models/bedrock/tests/test_inference_profile_exceptions.py (new) covers the three new branches end-to-end against the real BedrockLargeLanguageModel class. models/bedrock/tests/conftest.py stubs the AIModelEntity dependency so the LLM constructor doesn't try to resolve real predefined models — the tests only exercise the error-handling branches.

$ uv run pytest tests/
test_invoke_inference_profile_raises_unknown_error_verbatim PASSED
test_invoke_inference_profile_wraps_client_error_as_invokeerror PASSED
test_invoke_inference_profile_wraps_keyerror_as_invokeerror PASSED
3 passed

The central invariant the first test pins: a NameError raised inside the inference-profile branch propagates as NameError (not InvokeError) — i.e. real bugs surface, not silent wrappers.

Risk

Low — strictly additive to the existing _invoke exception handler. The only behavior change is that unknown errors now propagate verbatim instead of being silently wrapped as InvokeError. The boto3 ClientError path and the KeyError path both still surface as InvokeError with the original message, so operators who rely on that contract see no change.

Release Notes

  • fix(bedrock): stop wrapping non-boto3 exceptions in _invoke's inference-profile branch as InvokeError. A NameError/TypeError/KeyError (or any other Exception) raised by _get_model_info, get_inference_profile_info, _generate_price_info, or the converse-stream call now propagates verbatim, so real bugs in the inference-profile path surface instead of being silently re-raised as a generic InvokeError. The ClientError (boto3 / AWS) path is unchanged and still surfaces as InvokeError with the original message. Bumps the bedrock plugin from 0.0.89 → 0.0.90.

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

The exception-handling change is small, but this plugin release is missing a top-level models/bedrock/manifest.yaml version bump and a non-empty ## Release Notes section in the PR description. Please update the branch against current main and add both before the next CI run. #3795 also contains these same Bedrock changes; please keep the two PR scopes separate.

@Taranum01
Taranum01 force-pushed the fix/3653-bedrock-exception branch from e92beea to cd7fceb Compare September 7, 2026 18:47
@Taranum01

Copy link
Copy Markdown
Contributor Author

All three points addressed in this force-push:

  1. Branch rebased on current main (was ~1.4k commits behind; one add/add conflict in models/bedrock/tests/conftest.py resolved by keeping upstream's sys.path setup and folding in this PR's make_llm fixture on top of the same sys.path.insert line).

  2. models/bedrock/manifest.yaml version bump: 0.0.83 → 0.0.84, in a separate chore(bedrock): bump version to 0.0.84 commit so the version delta is greppable.

  3. ## Release Notes section added at the bottom of the PR description summarising the change (one bullet covering the exception-handling fix and the version bump).

  4. Scopes separated from fix(openai_api_compatible): route VIDEO attachments through video_url content part (#3696) #3795: the bedrock commit e92beeaa was duplicated in fix(openai_api_compatible): route VIDEO attachments through video_url content part (#3696) #3795's branch — rebased fix(openai_api_compatible): route VIDEO attachments through video_url content part (#3696) #3795 onto current main and skipped the bedrock commit there, so fix(openai_api_compatible): route VIDEO attachments through video_url content part (#3696) #3795 now contains only the openai_api_compatible VIDEO routing change (and its own 0.0.66 → 0.0.67 manifest bump + Release Notes section).

mergeable: MERGEABLE on both PRs now. Ready for the next CI run.

Taranum01 and others added 2 commits September 25, 2026 01:04
…nference-profile branch (langgenius#3653)

The _invoke inference-profile branch in models/llm/llm.py ended
with a bare `except Exception as e: raise InvokeError(str(e))`.
A NameError, TypeError, KeyError, or any other non-InvokeError
exception raised inside the try block (by _get_model_info,
get_inference_profile_info, _generate_with_converse, or any of
the dict accessors) surfaced to the caller as a generic
InvokeError whose message contained the original exception string,
hiding the root cause and traceback.

This is the same anti-pattern that PR langgenius#3565 (issue langgenius#3564) fixed
in _generate, and PR langgenius#3661 (issue langgenius#3661) fixed in
_generate_with_converse. The fix mirrors both:

  - except (ClientError, KeyError) as ex:
      Real AWS-boto3 client errors and dict-access KeyErrors are
      still wrapped as InvokeError so the operator sees the message
      ("ResourceNotFoundException: ..." etc.).
  - except Exception as ex:
      Unknown errors (NameError, TypeError, AttributeError, ...)
      re-raise verbatim so the operator sees the real traceback
      instead of a misleading InvokeError.

`tests/test_inference_profile_exceptions.py` (new) covers the three
new branches end-to-end against the real BedrockLargeLanguageModel
class. The first test asserts the central invariant the fix
preserves: a NameError raised inside the inference-profile branch
propagates as NameError (not InvokeError). The second and third
tests assert that boto3 ClientError and KeyError are still wrapped
as InvokeError so the operator sees the bad-key/bad-resource
message.

All three tests pass. `uv run pytest tests/` is the run command
and uses an empty AIModelEntity list (no real model schemas) so
the LLM constructor doesn't try to resolve real predefined
models — the test only exercises the error-handling branches.

Low — strictly additive to the existing _invoke exception
handler. The only behavior change is that unknown errors now
propagate verbatim instead of being silently wrapped as
InvokeError. The boto3 ClientError path and the KeyError path
both still surface as InvokeError with the original message, so
operators who rely on that contract see no change.
@Taranum01
Taranum01 force-pushed the fix/3653-bedrock-exception branch from cd7fceb to ed5c458 Compare September 24, 2026 19:35
@crazywoola

Copy link
Copy Markdown
Member

Thank you for your contribution, @Taranum01! This PR currently has merge conflicts with main, so we are closing it for now. Please update your branch against the latest main and resolve the conflicts — note that the consolidated dependency refresh (#4106–#4111) has bumped plugin manifest.yaml versions on main, so please bump models/bedrock/manifest.yaml to the next unused version when you rebase. You are welcome to open a new PR with the updated changes and link back to this one. We appreciate your time and effort!

If these changes are still wanted, they can be folded into #4095 when you update it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(bedrock): bare except Exception in _invoke inference-profile branch wraps real bugs as InvokeError

3 participants