Skip to content

validate Command

The validate command validates a policy pack’s structure, syntax, and type correctness without executing policies. This is useful for checking that your policies are correctly formatted and can be loaded before deployment.

Terminal window
sentrie validate <FQN> [OPTIONS]

The validate command performs comprehensive validation of a policy pack:

  1. Pack Loading: Validates the pack file (sentrie.pack.toml) structure
  2. Program Loading: Loads and parses all .sentrie policy files
  3. Index Validation: Validates namespace, policy, and rule references
  4. Type Checking: Validates type annotations and constraints
  5. Executor Creation: Attempts to create an executor to verify the pack is executable

If validation succeeds, the command exits with code 0. If any validation fails, it exits with a non-zero code and displays error messages.

The Fully Qualified Name (FQN) that identifies the namespace and policy to validate. The rule component is optional but can be included for reference.

Format: namespace/policy or namespace/policy/rule

Examples:

  • user_management/user_access - Validate the user_access policy
  • com/example/auth/access_control - Validate a policy in a nested namespace
  • com/example/auth/access_control/check_permission - Validate with rule reference (rule is not validated, only used for context)

Specifies the directory containing the policy pack to validate.

Terminal window
sentrie validate user_management/user_access --pack-location ./my-policy-pack

Default: ./ (current directory)

Examples:

  • --pack-location ./policies - Validate policies from ./policies directory
  • --pack-location /path/to/policy-pack - Validate policies from absolute path

Provides facts as a JSON string for type checking. This helps validate that fact declarations match expected types.

Terminal window
sentrie validate user_management/user_access --facts '{"user":{"role":"admin","status":"active"}}'

Default: {} (empty object)

Note: The --facts flag is primarily used for type checking. The validation process will verify that:

  • Fact types match their declarations
  • Required facts are present
  • Optional facts are correctly marked
  • Shape constraints are satisfied

Validate a policy pack in the current directory

Section titled “Validate a policy pack in the current directory”
Terminal window
sentrie validate user_management/user_access

Validate a policy pack from a specific location

Section titled “Validate a policy pack from a specific location”
Terminal window
sentrie validate com/example/auth/access_control \
--pack-location ./policy-pack
Terminal window
sentrie validate user_management/user_access \
--facts '{"user":{"role":"admin","status":"active"}}'
Terminal window
sentrie validate com/example/billing/pricing \
--pack-location ./policies

The validate command checks:

  • Validates sentrie.pack.toml exists and is correctly formatted
  • Checks pack metadata (name, version, schema version)
  • Parses all .sentrie files in the pack
  • Validates namespace declarations
  • Checks policy and rule syntax
  • Verifies shape definitions
  • Validates type annotations on facts, variables, and expressions
  • Checks shape field types and constraints
  • Verifies constraint validations (min, max, length, etc.)
  • Validates namespace, policy, and rule references
  • Checks that imported rules exist
  • Verifies exported shapes are accessible
  • Validates rule imports and exports
  • Attempts to create a runtime executor
  • Validates that all TypeScript modules can be loaded
  • Checks that all dependencies are resolvable
  • 0 - Validation succeeded
  • 1 - Validation failed (with error messages)

Common validation errors include:

  • Pack loading errors: Invalid pack file structure or missing pack file
  • Syntax errors: Invalid policy syntax or grammar violations
  • Type errors: Type mismatches or invalid type annotations
  • Reference errors: Missing namespaces, policies, or rules
  • Constraint violations: Values that don’t satisfy shape constraints
  • Module errors: Missing or invalid TypeScript modules

Validate policies before deploying to production:

Terminal window
sentrie validate com/example/auth/access_control \
--pack-location ./policies

Use in CI/CD pipelines to catch errors early:

#!/bin/bash
if ! sentrie validate com/example/auth/access_control; then
echo "Validation failed!"
exit 1
fi

Validate that facts match expected types:

Terminal window
sentrie validate user_management/user_access \
--facts '{"user":{"role":"admin","status":"active"}}'
Featurevalidateexec
Executes policies❌ No✅ Yes
Validates structure✅ Yes✅ Yes
Validates types✅ Yes✅ Yes
Shows results❌ No✅ Yes
Output formatText errorsTable/JSON
Use casePre-deploymentTesting/Execution