fix: narrow Bedrock _init_clients except to credential errors only

The bare `except Exception` would silently swallow `TypeError`,
`AttributeError`, and other real bugs in `_build_sync_client` with
only a debug log. The intent is to defer on missing AWS credentials,
which boto3 surfaces as `BotoCoreError` / `ClientError` (and `ValueError`
for some validation paths). Catch only those; let everything else
propagate so genuine failures stay loud.
This commit is contained in:
Greyson LaLonde
2026-04-12 05:43:03 +08:00
parent 755b1f21e0
commit 4c3ff7ddae

View File

@@ -310,10 +310,14 @@ class BedrockCompletion(BaseLLM):
"""Eagerly build the sync client when AWS credentials resolve,
otherwise defer so ``LLM(model="bedrock/...")`` can be constructed
at module import time even before deployment env vars are set.
Only credential/SDK errors are caught — programming errors like
``TypeError`` or ``AttributeError`` propagate so real bugs aren't
silently swallowed.
"""
try:
self._client = self._build_sync_client()
except Exception as e:
except (BotoCoreError, ClientError, ValueError) as e:
logging.debug("Deferring Bedrock client construction: %s", e)
self._async_exit_stack = AsyncExitStack() if AIOBOTOCORE_AVAILABLE else None
return self