guardrails
guardrails copied to clipboard
Guardrails Configure Issue and Cannot import name from guardrails.hub
Hello,
When I am in jupyter notebook, I type in from guardrails.hub import ToxicLanguage
I get, ImportError: cannot import name 'ToxicLanguage' from 'guardrails.hub' (C:\ProgramFilesFolder\Lib\site-packages\guardrails\hub_init_.py)
When I type in guardrails configure in anaconda prompt and my token, I get this error message:
C:\Users\tomlee>guardrails configure Token (optional) [▬]: Enable anonymous metrics reporting? [Y/n]: n --- Logging error --- Traceback (most recent call last): File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\guardrails\cli\server\hub_client.py", line 130, in get_auth token = get_jwt_token(creds) ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\guardrails\cli\server\hub_client.py", line 89, in get_jwt_token JWT().decode(token, do_verify=False) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\jwt\jwt.py", line 90, in decode message_bin = self._jws.decode(message, key, do_verify, algorithms) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\jwt\jws.py", line 93, in decode self._decode_segments(message) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\jwt\jws.py", line 81, in _decode_segments header = json.loads(b64decode(header_b64).decode('ascii')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'ascii' codec can't decode byte 0x96 in position 15: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\logging_init_.py", line 1160, in emit
msg = self.format(record)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\logging_init_.py", line 999, in format
return fmt.format(record)
^^^^^^^^^^^^^^^^^^
File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\logging_init_.py", line 703, in format
record.message = record.getMessage()
^^^^^^^^^^^^^^^^^^^
File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\logging_init_.py", line 392, in getMessage
msg = msg % self.args
~~~~^~~~~~~~~~~
TypeError: not all arguments converted during string formatting
Call stack:
File "
I expect to be able to get past that error, and then be able to get past the error for guardrails.hub import ToxicLanguage.
Additional context I also have this issue with check_for_pii, secrets_detection, text_summarization_quality, on_topic_validation, toxic_language, and competitors_check.
when doing guardrails hub install hub://guardrails/xxx I get the below ascii unicode error.
(base) C:\Users\tomlee>guardrails hub install hub://guardrails/detect_pii Installing hub://guardrails/detect_pii... --- Logging error --- Traceback (most recent call last): File "C:\ProgramFilesFolder\Lib\site-packages\guardrails\cli\server\hub_client.py", line 110, in get_validator_manifest module_manifest = fetch_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramFilesFolder\Lib\site-packages\guardrails\cli\server\hub_client.py", line 101, in fetch_module token = get_jwt_token(creds) ^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramFilesFolder\Lib\site-packages\guardrails\cli\server\hub_client.py", line 89, in get_jwt_token JWT().decode(token, do_verify=False) File "C:\ProgramFilesFolder\Lib\site-packages\jwt\jwt.py", line 90, in decode message_bin = self._jws.decode(message, key, do_verify, algorithms) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramFilesFolder\Lib\site-packages\jwt\jws.py", line 93, in decode self._decode_segments(message) File "C:\ProgramFilesFolder\Lib\site-packages\jwt\jws.py", line 81, in _decode_segments header = json.loads(b64decode(header_b64).decode('ascii')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'ascii' codec can't decode byte 0x96 in position 15: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramFilesFolder\Lib\logging_init_.py", line 1110, in emit
msg = self.format(record)
^^^^^^^^^^^^^^^^^^^
File "C:\ProgramFilesFolder\Lib\logging_init_.py", line 953, in format
return fmt.format(record)
^^^^^^^^^^^^^^^^^^
File "C:\ProgramFilesFolder\Lib\logging_init_.py", line 687, in format
record.message = record.getMessage()
^^^^^^^^^^^^^^^^^^^
File "C:\ProgramFilesFolder\Lib\logging_init_.py", line 377, in getMessage
msg = msg % self.args
~~~~^~~~~~~~~~~
TypeError: not all arguments converted during string formatting
Call stack:
File "
@account2433 I'm taking a look at this. Could you please share the following information to help us reproduce the issue?
- version of
guardrails-aiyou are using - Exact commands or code you are executing when you encounter these errors
- Any other relevant information to replicate the environment you are using such as:
- Operating System (Linux, MacOS, Window, WSL, etc.)
- Package manager you used to install
guardrails-ai(pip, poetry, conda, etc.) - Whether you are using a virtual environment and, if so, which tool (venv, virtualenv, etc.)
@account2433 I'm taking a look at this. Could you please share the following information to help us reproduce the issue?
version of
guardrails-aiyou are usingExact commands or code you are executing when you encounter these errors
Any other relevant information to replicate the environment you are using such as:
- Operating System (Linux, MacOS, Window, WSL, etc.)
- Package manager you used to install
guardrails-ai(pip, poetry, conda, etc.)- Whether you are using a virtual environment and, if so, which tool (venv, virtualenv, etc.)
The version is the latest I believe, 0.4.5.
The exact commands to get this to happen,
- in anaconda prompt, type in pip install guardrails-ai
- in anaconda prompt, type in guardrails configure token key The error then happens.
As per downloading the specific packages, the errors happen when I type in guardrails hub install hub://guardrails/package
I am using Windows.
The package manager is pip.
Using palo lato prisma vpn.
Ty!
@account2433 Thank you for the extra information! We'll look into this and let you know once we find something.
Hi @account2433,
We've looked into the issue and were able to reproduce. It seems that when one pastes the api key / token from the browser into PowerShell during guardrails configure it will seemingly paste the caret characters ^C instead of the actual token. If you use right click to paste it, it should paste the correct contents. Also one can add the token directly to the config file in ~/.guardrailsrc.
Let me know if this solves the issue for you, cheers!
Hi @account2433,
We've looked into the issue and were able to reproduce. It seems that when one pastes the api key / token from the browser into PowerShell during
guardrails configureit will seemingly paste the caret characters^Cinstead of the actual token. If you use right click to paste it, it should paste the correct contents. Also one can add the token directly to the config file in~/.guardrailsrc.Let me know if this solves the issue for you, cheers!
Thank you very much all for your help. Unfortunately I am still having the same issues. To make this easier to read, the code I type in is in italics, the result or output is in bold, and my notes are in regular font.
In anaconda prompt, I again typed in guardrails configure token followed by right clicking and pasting my token as prescribed in the instructions above. In return the result is: **Token (optional) [eyJhbGciOiJlUzl1NilslnR5cCl6lkpXVCJ9.eyJzdWliOiJnaXRodWJ8MTc0MjcwMzg2liwiaWF0ljoxNzE5Nzc1MTE0LCJleHAiOjE3MjlzNjcxMTR9.TAIIMxFpAwnqmcj0zhqMK9eAsSreASGyxkl2mSU9ZWI]: **
Weirdly I cannot type in anything after the colons, so I just hit enter, the result is Enable anonymous metrics reporting? [Y/n]: so I type in Y and then hit enter. The result is
"Try 'guardrails configure --help' for help. Error Got unexpected argument. (my token) (base) C:\Users\tomlee>"
So after this, again in anaconda prompt, I type in guardrails hub install hub://guardrails/valid_length and the result is the same issue I have been having, where the output/result is
**(base) C:\Users\tomlee>guardrails hub install hub://guardrails/valid_length Installing hub://guardrails/valid_length... --- Logging error --- Traceback (most recent call last): File "C:\ProgramFilesFolder\Lib\site-packages\guardrails\cli\server\hub_client.py", line 110, in get_validator_manifest module_manifest = fetch_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramFilesFolder\Lib\site-packages\guardrails\cli\server\hub_client.py", line 101, in fetch_module token = get_jwt_token(creds) ^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramFilesFolder\Lib\site-packages\guardrails\cli\server\hub_client.py", line 89, in get_jwt_token JWT().decode(token, do_verify=False) File "C:\ProgramFilesFolder\Lib\site-packages\jwt\jwt.py", line 90, in decode message_bin = self._jws.decode(message, key, do_verify, algorithms) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\ProgramFilesFolder\Lib\site-packages\jwt\jws.py", line 93, in decode self._decode_segments(message) File "C:\ProgramFilesFolder\Lib\site-packages\jwt\jws.py", line 81, in _decode_segments header = json.loads(b64decode(header_b64).decode('ascii')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'ascii' codec can't decode byte 0x96 in position 15: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramFilesFolder\Lib\logging_init_.py", line 1110, in emit
msg = self.format(record)
^^^^^^^^^^^^^^^^^^^
File "C:\ProgramFilesFolder\Lib\logging_init_.py", line 953, in format
return fmt.format(record)
^^^^^^^^^^^^^^^^^^
File "C:\ProgramFilesFolder\Lib\logging_init_.py", line 687, in format
record.message = record.getMessage()
^^^^^^^^^^^^^^^^^^^
File "C:\ProgramFilesFolder\Lib\logging_init_.py", line 377, in getMessage
msg = msg % self.args
~~~~^~~~~~~~~~~
TypeError: not all arguments converted during string formatting
Call stack:
File "
In the above instructions, for my configure.py, I manually put in the token in the quotes for where it says DEFAULT_TOKEN = "" and then reran the guardrails hub install hub://guardrails/valid_length in anaconda prompt, and I getting the same above error.
I hope to be able to move past this error so when in for example a Jupyter notebook, I can run for example the code from guardrails.hub import RegexMatch and begin utilizing the various guardrails.
I am having the same issue, if I go back to version 0.4.4 it works fine
I am having the same issue, if I go back to version 0.4.4.4 it works fine
Thank you, I installed version 0.4.4 via pip install guardrails-ai==0.4.4, but am still getting the same errors as above. For example again, when I type in guardrails configure and then right click in my token, then hit enter, it again returns that
Token (optional) [eyJhbGciOiJlUzl1NilslnR5cCl6lkpXVCJ9.eyJzdWliOiJnaXRodWJ8MTc0MjcwMzg2liwiaWF0ljoxNzE5Nzc1MTE0LCJleHAiOjE3MjlzNjcxMTR9.TAIIMxFpAwnqmcj0zhqMK9eAsSreASGyxkl2mSU9ZWI]:
which I notice in the documentation is not addressed.
Hi @androettop @account2433 apologize for the delay here, we are attempting to reproduce this on our end. Could you please provide what Windows version and version of powershell you are using? Any additional info that you could think of relating to your setup would also help 🙏🏼
Also if you are feeling up to it there are some suspicions around config file encoding that would be great to rule out:
-
Namely in
guardrails/classes/credentials.py: if we made the change fromwith open(guardrails_rc) as rc_file:towith open(guardrails_rc, encoding="utf-8") as rc_file: -
In
guardrails/cli/configure.pymade the change to:with open(guardrails_rc, "w") as rc_file:towith open(guardrails_rc, "w", encoding="utf-8") as rc_file: -
Delete the config file in
$HOME/.guardrailsrc -
Try the flow again
I have gone back to version 0.4.5 after several tests and now it is working, I am not sure what steps I followed to solve it. but among the things I did I have removed the whole python virtual environment and recreated it.
The problem started to appear after upgrading from v 0.4.4 to v 0.4.5, so maybe that can be a good starting point for testing.
I'm using WSL with Ubuntu
We've recently released a new candidate on PyPi that might resolve the issue you've encountered. Please try installing it with the version below. Just a note: you may need to delete the config file again before testing. This version includes additional changes, so it would be best to narrow its usage to simply determining if the issue persists.
pip install guardrails-ai==0.5.0a12
It would be great if you could confirm whether it works in a fresh environment and see if the issue is still reproducible. Your feedback will help us ensure the latest version has fixed the problem. Thank you!
Alternatively if you want to keep your current version there's a chance the following command may work
export PYTHONUTF8=1(ensuring all guardians commands are run on same shell as the previous command and deleting config file prior)
Also if you are feeling up to it there are some suspicions around config file encoding that would be great to rule out:
- Namely in
guardrails/classes/credentials.py: if we made the change fromwith open(guardrails_rc) as rc_file:towith open(guardrails_rc, encoding="utf-8") as rc_file:- In
guardrails/cli/configure.pymade the change to:with open(guardrails_rc, "w") as rc_file:towith open(guardrails_rc, "w", encoding="utf-8") as rc_file:- Delete the config file in
$HOME/.guardrailsrc- Try the flow again
thanks much for the teams help. it seemed like this above, specifically steps one and two, have now allowed me to download and install the validators by running guardrails hub install hub://guardrails/xxx. That being said, I still get the same error when doing guardrails configure my_token.
The more important task was being able to run the guardrails hub install hub://guardrails/xxx in my prompt so in that way this issue has been resolved. Ty!
Hello,
When I am in jupyter notebook, I type in from guardrails.hub import ToxicLanguage
I get, ImportError: cannot import name 'ToxicLanguage' from 'guardrails.hub' (C:\ProgramFilesFolder\Lib\site-packages\guardrails\hub__init__.py)
When I type in guardrails configure in anaconda prompt and my token, I get this error message:
C:\Users\tomlee>guardrails configure Token (optional) [▬]: Enable anonymous metrics reporting? [Y/n]: n --- Logging error --- Traceback (most recent call last): File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\guardrails\cli\server\hub_client.py", line 130, in get_auth token = get_jwt_token(creds) ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\guardrails\cli\server\hub_client.py", line 89, in get_jwt_token JWT().decode(token, do_verify=False) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\jwt\jwt.py", line 90, in decode message_bin = self._jws.decode(message, key, do_verify, algorithms) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\jwt\jws.py", line 93, in decode self._decode_segments(message) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\jwt\jws.py", line 81, in _decode_segments header = json.loads(b64decode(header_b64).decode('ascii')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'ascii' codec can't decode byte 0x96 in position 15: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\logging__init__.py", line 1160, in emit msg = self.format(record) ^^^^^^^^^^^^^^^^^^^ File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\logging__init__.py", line 999, in format return fmt.format(record) ^^^^^^^^^^^^^^^^^^ File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\logging__init__.py", line 703, in format record.message = record.getMessage() ^^^^^^^^^^^^^^^^^^^ File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\logging__init__.py", line 392, in getMessage msg = msg % self.args ~~~~^~~~~~~~~~~ TypeError: not all arguments converted during string formatting Call stack: File "", line 198, in run_module_as_main File "", line 88, in run_code File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Scripts\guardrails.exe__main.py", line 7, in sys.exit(cli()) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\typer\main.py", line 311, in call return get_command(self)(*args, **kwargs) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1157, in call return self.main(*args, **kwargs) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\typer\core.py", line 783, in main return _main( File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\typer\core.py", line 225, in _main rv = self.invoke(ctx) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 783, in invoke return __callback(*args, **kwargs) File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\typer\main.py", line 683, in wrapper return callback(**use_params) # type: ignore File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\guardrails\cli\configure.py", line 84, in configure get_auth() File "C:\Users\tomlee\AppData\Local\Programs\Python\Python312\Lib\site-packages\guardrails\cli\server\hub_client.py", line 141, in get_auth logger.error("An unexpected error occurred!", e) Message: 'An unexpected error occurred!' Arguments: (UnicodeDecodeError('ascii', b'{"alg":"eS9u6)l\x96typ)z\x96JWT"}', 15, 16, 'ordinal not in range(128)'),) Failed to authenticate!
I expect to be able to get past that error, and then be able to get past the error for guardrails.hub import ToxicLanguage.
Additional context I also have this issue with check_for_pii, secrets_detection, text_summarization_quality, on_topic_validation, toxic_language, and competitors_check.
May I know did you get this solved? if so how did you resolve. I have installed guardrails-ai-0.5.2, facing same issue as you discribed.
Hey @Paniraj2010, sorry that you're having issues with the latest guardrails. Just have a few questions that will help me get a better sense of what's going on.
- Are you using Windows?
- Also, if you display the configuration file in your $HOME directory
~/.guardrailsrcdo you see a valid string undertoken? If so, does it look like a valid JWT token?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.
This issue was closed because it has been stalled for 14 days with no activity.