ory/kratos · error

the provided number is not a valid phone number

Error message

the provided number is not a valid phone number

What it means

NormalizeIdentifier parses a value with the phonenumbers library when the schema annotation requests phone normalization. If the parsed number is not a valid phone number for any region, it refuses to normalize and returns this error, because storing an invalid E.164 identifier would corrupt identity matching.

Solutions

  1. Provide the number in full international E.164 format, e.g. +14155552671
  2. Add a default country code in the identity schema's normalization options so national formats can be resolved
  3. Validate the phone number client-side (format + plausible country) before submitting the flow
  4. Fix imported/migrated data with a phone validation library before creating identities

Example fix

// before
{"traits": {"phone": "555-1234"}}
// after
{"traits": {"phone": "+14155551234"}}
Defensive patterns

Strategy: validation

Validate before calling

p, err := phonenumbers.Parse(value, defaultRegion); if err != nil || !phonenumbers.IsValidNumber(p) { /* reject before submit */ }

Prevention

When it happens

Trigger: Registering/submitting a trait whose identity schema uses the phone normalization annotation, with a string that parses but fails phonenumbers.IsValidNumber (wrong country code, impossible number, or a non-phone string like '12345').

Common situations: Users typing a national number without a country code that cannot be inferred; placeholders like '000-000-0000'; schemas defaulting to region '' so no default country applies; migration scripts importing junk phone values.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of ory/kratos@b86338da04 (2026-09-07). Data as JSON: /api/errors/0890647d04faad2a. Report an issue: GitHub.

Appendix: source

Thrown at x/normalize.go:158

			return "", err
		}
		email, err := mail.ParseAddress(value)
		if err != nil {
			return "", err
		}
		return email.Address, nil

	case "sms":
		value, err := applyPRECIS(phoneProfile, value, false)
		if err != nil {
			return "", err
		}
		number, err := phonenumbers.Parse(value, "")
		if err != nil {
			return "", err
		}
		if !phonenumbers.IsValidNumber(number) {
			return "", errors.New("the provided number is not a valid phone number")
		}
		return phonenumbers.Format(number, phonenumbers.E164), nil

	case "username":
		fallthrough
	default:
		return applyPRECIS(emailProfile, value, true)
	}
}

View on GitHub (pinned to b86338da04)