Best Practices

Build AI automations that are reliable, reviewable, and easy to improve.

A workflow that succeeds once is a prototype; a workflow that remains correct, secure, observable, and maintainable as data, systems, people, and policies change is a production automation. Best practices turn isolated steps into dependable operational systems.

Start with the Business Outcome

Define the customer or business problem, current baseline, target outcome, owner, constraints, and unacceptable failure before choosing a platform or model. Useful success measures include cycle time, error rate, response time, rework, cost per case, and customer satisfaction—not merely the number of automated runs.

  • Identify who benefits and who could be harmed by an error.
  • Measure the existing process before claiming improvement.
  • Choose a narrow first scope with a clear beginning and end.
  • Document what the workflow will not automate.
  • Assign accountable business and technical owners.

Map and Simplify the Process

Document triggers, inputs, participants, systems, decisions, approvals, outputs, exceptions, and systems of record. Remove unnecessary handoffs and duplicate entry before implementation. Automation should not preserve a broken process merely because it already exists.

Use AI Only Where It Adds Value

Use Deterministic Logic ForUse AI Assistance For
Permissions, consent, thresholds, calculations, and policySummarization and language understanding
Required fields, allowed values, and state transitionsClassification when rules are insufficient
Financial, access, retention, and compliance controlsExtraction from unstructured text or documents
Retries, timeouts, scheduling, and routing rulesDrafting content for review
Authoritative business factsRecommendations with evidence and uncertainty

Do not use a model for a rule that can be expressed exactly and tested easily. Probabilistic output increases evaluation, oversight, and operational requirements.

Keep Workflows Modular

  • Give each workflow or subflow one clear responsibility.
  • Separate triggers, validation, AI processing, approvals, external actions, and notifications when useful.
  • Reuse well-tested components for authentication, retries, logging, and common transformations.
  • Define explicit input and output contracts between modules.
  • Avoid hidden cross-workflow state and circular triggers.
  • Prefer understandable control flow over clever compression.

Use Clear Names and Documentation

ItemGood Naming Pattern
Workflowverb + object + purpose, such as Route Support Tickets
Stepaction + target, such as Validate Customer Email
Connectionsystem + environment + permission, such as CRM Production Read-Only
Variablemeaning and unit, such as retry_delay_seconds
Alertimpact and workflow, such as Invoice Backlog Exceeds SLA
Versionrecorded release or revision identifier

Documentation should include purpose, diagram, owner, inputs, outputs, systems of record, permissions, schedules, dependencies, AI models and prompts, approval policy, failure behavior, metrics, runbook, and change history.

Validate at Every Boundary

  • Authenticate the source and verify webhook signatures when supported.
  • Validate required fields, types, formats, sizes, ranges, and allowed values.
  • Normalize dates, time zones, identifiers, phone numbers, and email addresses.
  • Treat files, links, user text, external API responses, and AI output as untrusted.
  • Validate destination, recipient, amount, permissions, and current state before an external action.
  • Reject or quarantine invalid data rather than silently guessing.
Output
Trigger
-> Authenticate source
-> Validate and normalize input
-> Deduplicate event
-> Retrieve authoritative context
-> Process with explicit rules and bounded AI
-> Validate proposed action
-> Approve when required
-> Execute idempotently
-> Verify and record result

Use Stable Identifiers and Idempotency

Networks, webhook providers, queues, and schedulers can deliver work more than once. Use stable event and business-record IDs, claim them atomically when necessary, and design create, send, payment, scheduling, and update operations so retries cannot repeat the effect.

  • Prefer immutable IDs over names, timestamps, or spreadsheet row numbers.
  • Store source event ID, attempt, workflow version, and external result ID.
  • Check current state before processing delayed or out-of-order events.
  • Define conflict handling for concurrent updates.
  • Use compensating actions and reconciliation for partial multi-system completion.

Design Error Handling by Category

FailurePreferred Response
Invalid inputReject or request correction; do not retry unchanged data
Temporary network or service errorRetry with increasing delay and bounded attempts
Rate limitHonor provider guidance and reduce concurrency
Expired authenticationPause affected work and notify the credential owner
Permission or policy failureRoute to an authorized reviewer
Low-quality AI outputReject, retry safely, use fallback, or request human review
Persistent unknown failurePreserve context, stop safely, and escalate

Never create infinite retries. Preserve failed work in a review or dead-letter queue, provide safe replay, and ensure replay still honors duplicate protection.

Set Timeouts and Resource Limits

  • Set connection, request, model, and total-workflow timeouts.
  • Limit payload size, file size, batch size, concurrency, and queue age.
  • Bound AI input, output, tool calls, recursion, and agent steps.
  • Apply cost and rate budgets to external services.
  • Choose an explicit policy for overlapping scheduled runs.
  • Fail safely when a limit is reached.

Constrain AI Inputs and Outputs

  • State the task, scope, approved sources, prohibited behavior, and output schema clearly.
  • Separate system instructions from untrusted content and retrieved documents.
  • Request structured output with fixed fields and allow-listed values.
  • Validate schema, types, ranges, references, and business rules after generation.
  • Ground factual responses in authoritative sources and preserve citations or source links.
  • Represent missing information as unknown instead of inviting guesses.
  • Prevent generated text from directly becoming a URL, query, command, recipient, or high-impact action without validation.
JSON
{
  "summary": "Customer reports an account-access problem after upgrade.",
  "category": "account_access",
  "priority": "high",
  "confidence": 0.87,
  "source_ids": ["ticket_T1042"],
  "needs_human_review": true
}

Defend Against Prompt Injection and Unsafe Tool Use

  • Treat user messages, emails, webpages, files, and retrieved text as data that may contain malicious instructions.
  • Allow-list tools, destinations, actions, and parameters available to the AI step.
  • Apply least privilege to every model-accessible integration.
  • Require deterministic authorization outside the model.
  • Show and approve material tool actions before execution when impact is high.
  • Do not expose secrets to prompts or return them through model output.

Use Human Review Based on Risk

Place review before external, irreversible, financial, legal, employment, safety, healthcare, access-control, or reputational actions. Review should be meaningful: show the original evidence, proposed action, AI rationale, policy, uncertainty, and changed fields.

  • Verify reviewer identity, role, and current authority.
  • Support approve, reject, edit, and request-more-information outcomes.
  • Set review deadlines and escalation paths.
  • Record decision, comments, timestamp, and workflow version.
  • Recheck state immediately before executing an approved action.
  • Provide a manual path when automation is unavailable.

Protect Credentials and Data

  • Store API keys, OAuth tokens, passwords, certificates, and signing secrets in protected credential systems.
  • Grant only required applications, scopes, records, fields, and actions.
  • Separate development, testing, and production identities and data.
  • Rotate or revoke access when exposure, ownership, or workflow status changes.
  • Encrypt sensitive data in transit and at rest according to requirements.
  • Minimize data collection, sharing, retention, logs, and AI prompts.
  • Review integration access and remove unused connections regularly.

Build Privacy and Compliance into the Design

  • Define the purpose and lawful or authorized basis for processing.
  • Honor consent, communication preferences, access, correction, deletion, and retention obligations.
  • Classify data and restrict cross-system and cross-border movement where required.
  • Avoid sending confidential or personal data to unapproved AI or external services.
  • Preserve audit evidence for regulated or consequential decisions.
  • Involve security, privacy, legal, finance, HR, or compliance owners according to risk.

Test Before Deployment

Test AreaExamples
Happy pathValid input and expected connected services
Input edge casesMissing, empty, malformed, oversized, duplicate, and contradictory values
Dependency failuresTimeout, outage, rate limit, expired credentials, and schema change
Workflow stateRetries, replay, overlap, cancellation, and partial completion
AI behaviorMalformed output, hallucination, injection, refusal, bias, and low confidence
Human reviewApproval, rejection, edit, timeout, and unauthorized reviewer
OperationsAlerts, dashboards, fallback, rollback, reconciliation, and runbooks

Use representative non-production data and safe destinations. Maintain a regression suite and versioned AI evaluation set so changes can be compared before release.

Deploy Safely

  • Use version control and peer review for workflow, prompt, schema, and policy changes.
  • Promote through development, staging, and production with environment-specific configuration.
  • Start with a small audience, shadow mode, dry run, or limited percentage where possible.
  • Define rollback, pause, kill-switch, and data-correction procedures before launch.
  • Record the deployed workflow, model, prompt, connector, and configuration versions.
  • Communicate ownership, support hours, known limitations, and fallback processes.

Monitor Technical and Business Outcomes

AreaExample Signals
ReliabilityTriggers, success, failure, retry, duplicate, and missed-event rates
PerformanceLatency, queue depth, oldest-item age, and throughput
AI qualityValidity, accuracy, groundedness, safety, override, and escalation rates
CostPlatform runs, model tokens, external API cost, and cost per successful outcome
BusinessCycle time, quality, conversion, resolution, and customer satisfaction
GuardrailsComplaints, policy violations, incorrect actions, and sensitive-data exposure

Use structured logs and correlation IDs, actionable alerts, dashboards for defined audiences, and runbooks for response. Monitor absence and silence: a workflow that stops receiving expected events may generate no explicit error.

Manage Cost and Scale

  • Batch work where latency requirements allow it.
  • Cache stable results with clear invalidation and privacy rules.
  • Use the smallest suitable model and send only required context.
  • Limit unnecessary retries, repeated enrichment, and duplicate notifications.
  • Apply controlled concurrency and respect provider quotas.
  • Measure cost per useful business outcome and set budgets and alerts.
  • Move beyond spreadsheets or no-code patterns when transactions, throughput, or control requirements demand it.

Maintain and Retire Workflows

  • Assign review dates for workflows, prompts, knowledge, credentials, dependencies, and policies.
  • Detect schema, input, concept, model, and business-outcome drift.
  • Update tests and runbooks after incidents and confirmed production failures.
  • Gather feedback from operators, reviewers, and affected users.
  • Archive stale data and revoke permissions when a workflow is retired.
  • Remove duplicate or low-value automation instead of accumulating complexity indefinitely.

Common Mistakes

MistakeBetter Practice
One giant workflowUse cohesive modules with documented contracts
Hard-coded credentials or IDsUse secret storage and environment configuration
Blindly trusting input or AI outputAuthenticate, validate, constrain, and review
Retrying every errorClassify failures and retry only temporary conditions
No duplicate protectionUse stable keys and idempotent effects
Automatic high-impact actionsAdd deterministic authorization and human approval
Testing only the happy pathTest failures, edge cases, abuse, and recovery
Monitoring only system uptimeMeasure output quality and business outcomes
No owner or runbookAssign accountability and document response procedures

Production Readiness Checklist

Output
[ ] Clear purpose, baseline, success metric, and owner
[ ] Documented inputs, outputs, systems of record, and boundaries
[ ] Authenticated trigger and validated data
[ ] Stable identifiers, idempotency, and concurrency policy
[ ] Structured, grounded, validated AI output
[ ] Human approval for high-impact actions
[ ] Least privilege, secret protection, privacy, and retention
[ ] Timeouts, bounded retries, error queue, and fallback
[ ] Happy-path, edge-case, security, AI, and recovery tests
[ ] Versioned deployment, rollback, and kill switch
[ ] Logs, metrics, traces, quality evaluation, alerts, and runbook
[ ] Review, maintenance, and retirement plan