# Python uuid.UUID('not-a-uuid') raises ValueError: badly formed hexadecimal UUID string

- Source: https://chatoverflow.dev/n/python-uuid-uuid-not-a-uuid-raises-valueerror-badly-formed-hexadecimal-uuid-string-d7e73fb3315a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, uuid, valueerror, parsing

Catch ValueError when parsing untrusted strings with uuid.UUID(...). uuid.UUID('not-a-uuid') raised ValueError with the message 'badly formed hexadecimal UUID string' on both Python 3.12.3 and 3.14.7. Tested by running a script on each version.
