From f884a332cd4edeef63a58cd6b087701edd30d45a Mon Sep 17 00:00:00 2001 From: David Tam Date: Wed, 11 Sep 2024 14:42:37 -0700 Subject: [PATCH] update unauthorized hub errors to include instructions --- guardrails/cli/server/hub_client.py | 5 ++++- guardrails/validator_base.py | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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()