Skip to main content
The 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:
  1. Collects attachments from all previous detection actions in the workflow
  2. Uploads files to Supabase storage in the violations bucket
  3. Creates violation records via the insert-violation edge function
  4. Returns violation IDs for use by subsequent actions

Requirements

RequirementDescription
Previous detection actionsAt least one detection action must have completed with attachments
Branch ruleValid branch rule ID for the violation
Storage bucketSupabase 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:
OptionTypeDefaultDescription
is_multiple_attachments_in_business_action_outputbooleanfalseWhen 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):
  1. result.extras['attachments'] - New unified ResultAttachment schema
  2. result.extras['full_attachment_paths'] or result.extras['detection_attachment_paths'] - Legacy list format
  3. result.full_attachment_path or result.detection_attachment_path - Legacy string format

Attachment types

TypeCategoryDescription
Main attachmentfullVideo clips or full-frame images
Sub attachmentdetectionCropped detection images

Upload process

All local files are uploaded to Supabase storage before creating violations. The action handles three input types:
Input typeHandling
Local file pathsUploaded to the violations bucket
URLsPassed through unchanged (already accessible)
Base64 dataDecoded, saved to a temporary file, then uploaded
The action caches upload results to avoid uploading the same file multiple times when creating separate violations.

Violation creation modes

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
Use case: When you want to track each detection as a separate incident for individual review and resolution.

Result format

Success result

When violations are created successfully, the result contains:
FieldValue
is_successtrue
feature_resultviolation created
noteSummary like “Created 3 violation(s)“
full_attachment_pathList of uploaded main attachment URLs
detection_attachment_pathList of uploaded sub attachment URLs
extras.violation_idsArray of all created violation UUIDs
extras.violation_idFirst violation ID (for backwards compatibility)
extras.attachmentsUnified attachment schema with type and category info

Failure result

When violation creation fails:
FieldValue
is_successfalse
feature_resultfailed
noteError description (e.g., “No valid attachments could be uploaded”)

Possible errors

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
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
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 violations bucket 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
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_id is 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:
  1. Configure a detect action to monitor the restricted area
  2. Add create_violation as the next step after detection
  3. Leave is_multiple_attachments_in_business_action_output as false (default)
Expected behavior: When someone is detected, the workflow creates a violation record with the detection crop image and video clip. Each detection becomes a separate violation that can be reviewed individually.

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:
  1. Configure a detect action with tracking enabled to monitor the queue
  2. Set up edge conditions to trigger when dwell time exceeds your threshold
  3. Add create_violation after the edge condition
  4. Set is_multiple_attachments_in_business_action_output to true on the rule
Expected behavior: When the edge condition triggers, all detection crops and video clips are combined into a single violation. The brand receives one notification with all the evidence grouped together.

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:
  1. First detect action identifies people
  2. Second detect action runs attribute detection on the crops (using image-from-previous-actions mode)
  3. create_violation collects attachments from both detection actions
Expected behavior: The violation includes both the original person detection crops and any attribute detection results. Notes from both detection actions are combined in the violation record.

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 in result.extras['violation_ids'] for subsequent actions to reference. Typical workflow flow:
  1. Detection action captures evidence and identifies violations
  2. Edge conditions determine if a violation should be created
  3. create_violation uploads attachments and creates database records
  4. 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.