CtroEnv
ctroenvType-Safe Environment Variables
Getting StartedQuick StartCore Concepts
defineEnv()string()number()boolean()semver()pick()ip(), ipv4(), ipv6()uuid(), guid()Chainable MethodsRefinementsError HandlingSchema CompositionSecurityCustom Validators
CLI Overviewctroenv validatectroenv generatectroenv checkctroenv docsctroenv initCLI Configuration
Node AdapterVite AdapterNext.js Adapter
Migration from t3-envMigration from envalidMigration from dotenv

uuid(), guid()

Create UUID and GUID validators for RFC 9562 and permissive formats.

  1. Docs
  2. Core API

uuid(), guid()

Creates validators that accept UUID and GUID strings.

Signature

function uuid(): UuidValidator
function guid(): UuidValidator

Accepted Values

uuid()

Accepts RFC 9562 UUIDs. Case-insensitive, requires hyphens. Optionally validates the version digit.

InputResult
"550e8400-e29b-41d4-a716-446655440000"✅ UUID v4
"550E8400-E29B-41D4-A716-446655440000"✅ Case-insensitive
"00000000-0000-0000-0000-000000000000"✅ Nil UUID
"018e0e00-9e4b-7b3c-9a1e-123456789abc"✅ UUID v7
"550e8400e29b41d4a716446655440000"❌ No hyphens
"not-a-uuid"❌ Not a UUID

Version-Specific UUID

// Restrict to a specific UUID version
uuid({ version: "4" })   // Only UUIDv4
uuid({ version: "7" })   // Only UUIDv7
uuid({ version: "any" }) // Any version (default)
Inputuuid({ version: "4" })uuid({ version: "7" })
"550e8400-e29b-41d4-a716-446655440000"✅ v4❌ not v7
"018e0e00-9e4b-7b3c-9a1e-123456789abc"❌ not v4✅ v7

Supported versions: "1", "2", "3", "4", "5", "6", "7", "8".

guid()

Permissive GUID format. Case-insensitive, no variant/version bit validation. Does not accept braces.

InputResult
"550e8400-e29b-41d4-a716-446655440000"✅
"{550e8400-e29b-41d4-a716-446655440000}"❌ Braces not accepted
"550E8400-E29B-41D4-A716-446655440000"✅ Uppercase accepted
"550e8400e29b41d4a716446655440000"❌ No hyphens

Refinements

UUID validators have no type-specific refinements. They support only the chainable methods (.optional(), .default(), .describe(), .secret(), .validate()).

Examples

const env = defineEnv({
  SESSION_ID: uuid(),
  CORRELATION_ID: uuid().optional(),
  UUIDV7_ONLY: uuid({ version: "7" }),
  LEGACY_GUID: guid().describe("Legacy GUID format identifier"),
})

How is this guide?

Edit on GitHub

Last updated on Jun 25, 2026

Previousip(), ipv4(), ipv6()NextChainable Methods

On this page

SignatureAccepted Values`uuid()`Version-Specific UUID`guid()`RefinementsExamples