create_violation business action collects detection results from previous workflow actions and creates violation records in the database. It handles attachment uploads to cloud storage and supports both single and combined attachment modes.
What it does
The create_violation action:- Collects attachments from all previous detection actions in the workflow
- Uploads files to Supabase storage in the
violationsbucket - Creates violation records via the
insert-violationedge function - Returns violation IDs for use by subsequent actions
Requirements
| Requirement | Description |
|---|---|
| Previous detection actions | At least one detection action must have completed with attachments |
| Branch rule | Valid branch rule ID for the violation |
| Storage bucket | Supabase storage bucket violations must exist |
Configuration
The create_violation action doesn’t require extensive configuration - it automatically collects data from previous actions. Simply add it to your workflow after detection actions.Rule-level options
Configure attachment behavior on the rule:| Option | Type | Default | Description |
|---|---|---|---|
is_multiple_attachments_in_business_action_output | boolean | false | When true, all attachments are combined into a single violation |
How it works
Attachment collection
The action iterates through all previous non-business actions and extracts attachments from their results. Attachment sources (in priority order):result.extras['attachments']- New unified ResultAttachment schemaresult.extras['full_attachment_paths']orresult.extras['detection_attachment_paths']- Legacy list formatresult.full_attachment_pathorresult.detection_attachment_path- Legacy string format
Attachment types
| Type | Category | Description |
|---|---|---|
| Main attachment | full | Video clips or full-frame images |
| Sub attachment | detection | Cropped detection images |
Upload process
All local files are uploaded to Supabase storage before creating violations. The action handles three input types:| Input type | Handling |
|---|---|
| Local file paths | Uploaded to the violations bucket |
| URLs | Passed through unchanged (already accessible) |
| Base64 data | Decoded, saved to a temporary file, then uploaded |
Violation creation modes
- Separate violations (default)
- Combined violations
Each detection creates a separate violation record. The action iterates through the collected attachments and creates one violation per detection.Attachment pairing logic:
- If there are equal numbers of main and sub attachments, they’re paired one-to-one
- If there’s only one main attachment (video), it’s reused for all sub attachments (detection crops)
- If there are more sub attachments than main, extra detections get the single video
Result format
Success result
When violations are created successfully, the result contains:| Field | Value |
|---|---|
is_success | true |
feature_result | violation created |
note | Summary like “Created 3 violation(s)“ |
full_attachment_path | List of uploaded main attachment URLs |
detection_attachment_path | List of uploaded sub attachment URLs |
extras.violation_ids | Array of all created violation UUIDs |
extras.violation_id | First violation ID (for backwards compatibility) |
extras.attachments | Unified attachment schema with type and category info |
Failure result
When violation creation fails:| Field | Value |
|---|---|
is_success | false |
feature_result | failed |
note | Error description (e.g., “No valid attachments could be uploaded”) |
Possible errors
No previous detection actions found
No previous detection actions found
Error message: No previous detection actions found for violation creationWhat happened: There are no non-business actions before create_violation in the workflow.How to fix:
- Ensure detection actions run before create_violation in your workflow
- Check workflow configuration for proper action ordering
- Verify the detection action completed successfully
No valid attachments
No valid attachments
Error message: No valid attachments found for violationWhat happened: Previous actions didn’t produce any attachment paths, or all uploads failed.How to fix:
- Verify detection actions are saving images and videos correctly
- Check that file paths in detection results are valid and accessible
- Ensure Supabase storage is accessible from the RES server
- Check detection action logs for file saving errors
Upload failed
Upload failed
Error message: Failed to upload to Supabase storageWhat happened: Storage upload failed due to permissions, connectivity, or file issues.How to fix:
- Check Supabase storage configuration and credentials
- Verify the
violationsbucket exists and has appropriate permissions - Check network connectivity to Supabase
- Ensure the local file exists and is readable
- Check disk space on the RES server
insert-violation failed
insert-violation failed
What happened: The edge function returned an error when creating the violation record.How to fix:
- Check edge function logs in Supabase for specific error details
- Verify the
branch_rule_idis valid and exists in the database - Ensure database constraints aren’t violated (unique keys, foreign keys)
- Check that required fields are not null
Practical examples
Example 1: Basic violation creation
Scenario: You have a detection workflow that identifies people in restricted areas and want to create violation records for each detection. Workflow setup:- Configure a detect action to monitor the restricted area
- Add create_violation as the next step after detection
- Leave
is_multiple_attachments_in_business_action_outputasfalse(default)
Example 2: Combined attachments for group events
Scenario: You’re monitoring a queue area and want to create a single violation when multiple people are detected waiting too long. Workflow setup:- Configure a detect action with tracking enabled to monitor the queue
- Set up edge conditions to trigger when dwell time exceeds your threshold
- Add create_violation after the edge condition
- Set
is_multiple_attachments_in_business_action_outputtotrueon the rule
Example 3: Cascading detection workflow
Scenario: You want to run a secondary detection model on crops from an initial detection (for example, detecting specific attributes on detected people). Workflow setup:- First detect action identifies people
- Second detect action runs attribute detection on the crops (using image-from-previous-actions mode)
- create_violation collects attachments from both detection actions
Attachment handling best practices
Use unified schema
Prefer the
result.extras['attachments'] format for new integrations. It supports type information, categories, and metadata for better tracking.Include both types
Always include both main (video) and sub (detection) attachments when possible. This provides complete evidence for violation review.
Handle URLs efficiently
If attachments are already URLs from previous uploads, they’re passed through without re-upload. This saves bandwidth and processing time.
Monitor storage usage
Violation attachments accumulate in Supabase storage. Implement retention policies to manage storage costs over time.
Integration with workflows
The create_violation action is typically placed after detection actions and before any notification steps. The violation IDs created are available inresult.extras['violation_ids'] for subsequent actions to reference.
Typical workflow flow:
- Detection action captures evidence and identifies violations
- Edge conditions determine if a violation should be created
- create_violation uploads attachments and creates database records
- Notification actions alert brands about the new violations
The violation lifecycle continues after creation. See the violation lifecycle documentation for details on escalation, nextRunTime management, and brand notifications.