Skip to content

Schema

The EnvGuard schema is a YAML file that declaratively defines the expected shape of your environment variables.

File Name

By default, EnvGuard looks for envguard.yaml in the current directory. You can specify a different file with --schema.

Top-Level Structure

yaml
version: "1.0"           # Schema version (required)
extends: "base.yaml"     # Optional: inherit from another schema file
env:                     # Map of variable names to definitions (required)
  VARIABLE_NAME:
    type: string
    required: true
    # ... more rules

secrets:                 # Optional: custom secret detection rules
  custom:
    - name: "my-token"
      pattern: "tk_[a-zA-Z0-9]{32}"
      message: "Custom token detected"

Variable Definition

Every variable under env: supports the following fields:

FieldTypesDescription
typeallRequired. Data type: string, integer, float, boolean, array
requiredallIf true, variable must be present and non-empty
defaultallFallback value injected when variable is absent
descriptionallHuman-readable documentation
messageallCustom error message on validation failure
patternstringRegex the value must match
enumstring, integer, float, arrayArray of allowed values
mininteger, floatMinimum numeric value (inclusive)
maxinteger, floatMaximum numeric value (inclusive)
minLengthstring, arrayMinimum length
maxLengthstring, arrayMaximum length
formatstringBuilt-in format validator (see below)
disallowstringArray of forbidden string values
requiredInallEnvironments where the variable is required
devOnlyallVariable only allowed in development
separatorarrayDelimiter for splitting array items
allowEmptyallIf false, reject empty strings
containsarrayRequire array to contain this item
dependsOnallName of another variable that triggers conditional requirement
whenallValue the dependsOn variable must have
deprecatedallWarning message shown when variable is present
sensitiveallRedact value in output
transformstringPre-validation transform: lowercase, uppercase, trim

Supported Types

string

yaml
API_KEY:
  type: string
  required: true
  pattern: "^[A-Za-z0-9_-]{32}$"

integer

yaml
PORT:
  type: integer
  default: 3000
  min: 1
  max: 65535

float

yaml
RATE_LIMIT:
  type: float
  default: 1.5
  min: 0.1
  max: 100.0

boolean

yaml
DEBUG:
  type: boolean
  default: false

Accepted values (case-insensitive): true, false, 1, 0, yes, no, on, off.

array

yaml
ALLOWED_HOSTS:
  type: array
  separator: ","
  default: "localhost,127.0.0.1"

Built-in Formats

FormatDescriptionExample
emailValid email addressuser@example.com
urlValid URLhttps://api.example.com
uuidUUID v4550e8400-e29b-41d4-a716-446655440000
base64Base64-encoded stringSGVsbG8gV29ybGQ=
ipIPv4 or IPv6 address192.168.1.1
portValid TCP/UDP port (1-65535)8080
jsonValid JSON{"key": "value"}
durationGo duration string5m30s
semverSemantic version1.2.3
hostnameValid hostnameapi.example.com
hexHexadecimal stringa1b2c3
cronCron expression0 0 * * *

Example Schema

yaml
version: "1.0"

env:
  DATABASE_URL:
    type: string
    required: true
    format: url
    description: "PostgreSQL connection string"

  PORT:
    type: integer
    default: 3000
    min: 1024
    max: 65535
    description: "HTTP server port"

  DEBUG:
    type: boolean
    default: false
    description: "Enable debug mode"

  LOG_LEVEL:
    type: string
    enum: [debug, info, warn, error]
    default: "info"
    description: "Logging verbosity"

  API_KEY:
    type: string
    required: true
    sensitive: true
    description: "External API key"

  ALLOWED_HOSTS:
    type: array
    separator: ","
    default: "localhost"
    description: "Comma-separated allowed hostnames"

Released under the MIT License.