diff --git a/guardrails/cli/server/hub_client.py b/guardrails/cli/server/hub_client.py index 89a7ac931..6e5950676 100644 --- a/guardrails/cli/server/hub_client.py +++ b/guardrails/cli/server/hub_client.py @@ -147,7 +147,10 @@ def get_validator_manifest(module_name: str): logger.error(f"Failed to install hub://{module_name}") sys.exit(1) return module_manifest - except HttpError: + except HttpError as e: + if e.message == "Unauthorized": + logger.error(TOKEN_INVALID_MESSAGE) + raise logger.error(f"Failed to install hub://{module_name}") sys.exit(1) except (ExpiredTokenError, InvalidTokenError) as e: diff --git a/guardrails/validator_base.py b/guardrails/validator_base.py index ce7484a18..9038210dd 100644 --- a/guardrails/validator_base.py +++ b/guardrails/validator_base.py @@ -280,7 +280,14 @@ def _hub_inference_request( } req = requests.post(validation_endpoint, data=request_body, headers=headers) if not req.ok: - logging.error(req.status_code) + if req.status_code == 401: + raise Exception( + "401: Remote Inference Unauthorized. Please run " + "`guardrails configure`. You can find a new" + " token at https://hub.guardrailsai.com/keys" + ) + else: + logging.error(req.status_code) return req.json()