Validation and Control Flow - Examples
Best practices and examples for the validations: block.
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
