Validation and control flow - examples
Best practices and examples for the validations: block.
Workflow mode only.
Best practices
Use skip for optional logic
yaml
# resources/example.yaml
validations:
skip:
- get('enableCache') != trueValidate early with check
yaml
# Good: Catch errors before expensive operations
validations:
check:
- get('userId') != null
- get('apiKey') != ''
error:
code: 400
message: "userId and apiKey are required"Restrict routes for security
yaml
# resources/example.yaml
validations:
routes: [/api/v1/admin]
methods: [POST]Combine all controls
yaml
# resources/example.yaml
validations:
methods: [POST]
routes: [/api/v1/admin]
headers: [Authorization]
check:
- get('adminToken') != null
error:
code: 401
message: Admin token required
skip:
- get('dryRun') == true
chat:
prompt: "Admin: {{ get('action') }}"Examples
Conditional processing
yaml
# resources/smart-processor.yaml
actionId: smartProcessor
name: Smart Processor
validations:
skip:
- get('process') != true
check:
- get('data') != null
- len(get('data')) > 0
error:
code: 400
message: Data is required
python:
script: |
data = get('data')
return process(data)Secure endpoint
yaml
# resources/secure-endpoint.yaml
actionId: secureEndpoint
name: Secure Endpoint
validations:
methods: [POST]
routes: [/api/v1/secure]
headers: [Authorization, Content-Type]
check:
- get('Authorization') != null
- get('Authorization') startsWith 'Bearer '
error:
code: 401
message: Valid authorization token required
chat:
prompt: "Secure: {{ get('q') }}"See also
- Validation and control flow - Full
validations:block reference - Expressions - Expression syntax for conditions
- Unified API - Using
get()in validations
