Why Is My UUID Invalid? Common Errors and Fixes
By SimpleTools24Published 4 min read
A UUID is rejected as invalid when its text doesn't parse as 32 hexadecimal digits in a recognised layout. The most common causes are invisible characters (spaces, line breaks, zero-width characters), the wrong number of digits from truncation or copy-paste errors, characters outside 0–9 and a–f (like the letter O instead of zero), and formats a particular parser doesn't accept, such as braces or missing hyphens. Less often, a strict validator rejects a correctly formatted UUID because its version or variant isn't what the code expects.
In this guide
Typical Error Messages
| Platform | Error | Meaning |
|---|---|---|
| PostgreSQL | invalid input syntax for type uuid: "..." | The text couldn't be parsed as a UUID |
| .NET | Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) | Wrong length or format for Guid.Parse |
| Java | Invalid UUID string: ... | UUID.fromString couldn't parse it |
| Python | ValueError: badly formed hexadecimal UUID string | uuid.UUID() rejected the input |
| JavaScript (uuid package) | Invalid UUID | parse() or stringify() got a malformed value |
| APIs | 400 Bad Request / validation failed | Server-side validation rejected the field |
Exact wording varies by version, but the causes are the same.
Cause 1: Hidden Whitespace and Invisible Characters
Copying from emails, spreadsheets, PDFs or chat apps often brings extra characters:
- Leading or trailing spaces and tabs
- Line breaks (
\n,\r\n) from copying a whole cell or line - Non-breaking spaces (U+00A0)
- Zero-width spaces (U+200B) or byte order marks
The UUID looks perfect on screen but has 37 or 38 characters. Fix: trim input before validating, and in data pipelines strip all whitespace and zero-width characters from ID fields.
Cause 2: Wrong Length
A valid UUID has exactly 32 hex digits (36 characters with hyphens). Common length problems:
- Truncation by a database column that's too short, a UI that shortens long text, or a log line cut off.
- Missing characters from manual typing.
- Extra characters from accidentally pasting two IDs together.
Count the hex digits, ignoring hyphens. If it's not 32, the value is damaged and needs to be fetched again from the source.
Cause 3: Characters That Aren't Hex
Only 0–9 and a–f (either case) are allowed. Look for:
- Letter O instead of zero, and lowercase L or capital I instead of one, often from retyping.
- Smart quotes or dashes: word processors replace
-with en dashes (–) and wrap text in curly quotes. - Quotes included in the value, such as
"9b2c1f7e-..."with literal quote marks after a CSV import.
Cause 4: A Format the Parser Doesn't Accept
Parsers differ:
- PostgreSQL accepts hyphens in standard positions, braces and the compact form, but not arbitrary hyphen placement.
- .NET's
Guid.Parseaccepts several formats;ParseExactwith "D" only accepts the standard hyphenated form. - Some APIs require lowercase canonical form only.
If a value works in one system and fails in another, compare their accepted formats. Normalise to lowercase hyphenated form before sending. UUID format explained lists the common forms.
Cause 5: Strict Version or Variant Checks
A correctly formatted UUID can still fail validation that requires a specific version, for example a v4-only regex receiving UUID v7 values after a system upgrade, or a strict check rejecting the nil UUID. Check the 13th digit (version) and 17th (variant). UUID regex patterns has version-agnostic patterns, and nil UUID and max UUID explains the special values.
Cause 6: Not a UUID at All
Sometimes the field contains something else entirely: a numeric ID, a ULID, a slug, or an object serialised as [object Object]. Check where the value came from and whether the API expects a UUID for that field.
A Quick Debugging Checklist
- Print the value with delimiters, such as
[${value}], to reveal whitespace. - Print its length; it should be 36 (or 32 without hyphens).
- Check for characters outside
0-9a-fA-F-. - Compare the format with what the receiving system accepts.
- Check version and variant if a strict validator is involved.
In code, prefer robust validation at the edges of your system; how to validate a UUID in JavaScript and Python shows how.
Checking Many Values at Once
When an import or migration fails, you often need to know which IDs are bad. Paste them into the UUID validator: it checks up to 1,000 lines, skips blank lines, accepts standard, compact, braced and URN forms, and shows which lines are invalid along with the canonical form of the valid ones. For a single suspicious value, the UUID decoder shows its version, variant and any embedded timestamp.
Frequently Asked Questions
What does "invalid input syntax for type uuid" mean?
PostgreSQL couldn't parse the text as a UUID. Check for whitespace, wrong length or non-hex characters.
Why does my UUID work in one app and fail in another?
The apps accept different formats or apply different version checks. Normalise to lowercase hyphenated form.
Can I repair a truncated UUID?
No. The missing digits can't be recovered; get the original value again.
Are UUIDs with uppercase letters invalid?
No. Uppercase is valid, although some strict APIs require lowercase.
Summary
Most invalid UUIDs are damaged by whitespace, truncation, look-alike characters or unsupported formats. Trim, count, check characters, normalise, and only then worry about version and variant rules.
Related tools
Related articles
- UUID Regex PatternsTested regex patterns for UUIDs, from loose format checks to strict version and variant validation, with examples.
- Validate a UUID in CodePractical validation in JavaScript and Python, plus notes for Java and C#, and how strict your checks should be.
- Nil UUID and Max UUIDThe all-zero and all-f special UUIDs, how languages expose them, and why an unexpected nil UUID is usually a bug.