Validate and preview a business rule (SOP) create or update.
when_to_use:
First step of every tenant SOP create or update — validates the
payload and issues the approval token.
Schema:
sop (required): {title, target_entity, operations, phase,
rule_text, priority?, enabled?}. target_entity: lead,
opportunity, party, quotation, salesOrder, salesInvoice,
purchaseInvoice, purchaseOrder, ticket, task, timeRecord, or
performanceRecord. operations: list of
read/create/update/delete. phase: before_search /
before_payload / before_preview / after_create / always.
priority: 1-100, lower runs first, default 50. enabled: bool,
default true. Plain text only — HTML, URLs, Markdown, and unsafe
Unicode are rejected; title max 120 chars, rule_text max 2000.
sop_id: existing SOP id for updates; omit for creates.
returns:
Dict with action (create_sop|update_sop), ready, validated_sop,
approval, current_sop_count, max_sops, execution envelope, and
next_steps. On validation failure ready is false and error
explains why.
preconditions:
Admin role (every plan). Creates require fewer than
MAX_SOPS_PER_TENANT existing SOPs; updates require an existing
sop_id.
post_effects:
Issues a single-use, payload-bound approval token; no Firestore
writes yet. Next step: call execute_approved with approval.token
and execution.payload.