OctiAI

Categories

Expense Approval: n8n Human-in-the-Loop Workflow Blueprint

Template prompt that converts a requirements brief into a deployable, node-by-node n8n workflow spec (OCR → routing → approvals → escalation) with mapping tables, retries, dedup...

What You'll Get

How to Use

Practical tweak to reduce duplicates and costs

Use a combined idempotency key formula (e.g., `sha256(source + '_' + source_id + '_' + submitted_at + '_' + image_phash)`) and a fuzzy image hash (pHash) threshold to dedupe before calling OCR; only call OCR after a quick dedupe check to reduce API calls and costs.

Works Best With

This prompt produces best results when you provide:

Prompt Template

## Goal
- Automate an expense approval human-in-the-loop workflow: receipt ingestion → OCR → rule-based routing → approval actions → escalation; include auditable mapping, idempotency, deduplication, retries, and fallbacks.

## Inputs
- Trigger: {{trigger_event}}  
- Apps/integrations: {{apps_list}}  
- Auth constraints and credential scope: {{auth_constraints}}  
- Incoming payload schema / important fields: {{data_schema}}  
- Escalation and SLA policy: {{escalation_policy}}  
- Failure policy: specify retry limits, escalation thresholds, and manual-queue rules (if not provided, the generated spec must request them)
- Idempotency key strategy and dedupe key (if not provided, the generated spec must propose a safe default)

If any of the above are missing or underspecified, the prompt below will instruct the model to return a concise list of required fields and example values before generating the workflow.

## Prompt
You are an expert n8n workflow designer. Produce a complete, operator-grade n8n workflow blueprint (node-by-node) that implements an expense approval human-in-the-loop pipeline. Use the following inputs: trigger = {{trigger_event}}, integrations = {{apps_list}}, auth constraints = {{auth_constraints}}, incoming payload schema = {{data_schema}}, escalation policy = {{escalation_policy}}. If any input above is missing, list the missing fields and give a short example for each, then stop.

Output a single copy-paste-ready specification that contains the sections listed in "Output Format". The specification must be concrete and actionable for an n8n implementation and must follow these requirements:

- Produce an ordered Node List for n8n. For each node include:
  - node type and exact n8n node name
  - trigger or activation condition
  - credentials required and minimal permission scope
  - full node settings and parameters (expressions where needed) — show example expressions for dynamic fields
  - input => output data shape (example JSON snippets)
  - explicit transformation steps (no abstract "transform" node without details)
  - downstream error handling path(s)
- Provide the Webhook schema or API payload expected at the trigger (content-type, example body) and the exact idempotency header/field to honour.
- Provide the OCR integration call spec (endpoint, payload, auth, response fragment mapping). If OCR is an external API, include an example HTTPS request payload and the expected response fields used downstream.
- Provide the Rule Engine / Router logic as an explicit Decision Node plan: list each rule, condition expression, target route, and fallback/default route.
- Provide the Human Approval step details: notification method(s), message template(s), approval actions (approve/reject/ask-for-more-info), expected back-channel payloads, and how the approval outcome maps back into the workflow.
- Provide Escalation flow: explicit triggers for escalation, escalation target(s), SLA timers, and example messages.
- Include Field Mapping Table(s) showing exact field-to-field mapping from trigger -> OCR -> parsed expense -> CRM/ERP/Accounting system, including data types, required/optional flag, and validation rules.
- Include Retries, Timeouts, and Dedupe/Idempotency strategy:
  - node-level retry counts, backoff, and conditions to retry vs escalate
  - global idempotency key generation formula (explicit expression using incoming fields)
  - dedupe algorithm for duplicate receipts (fuzzy image hash + fields), and merge policy
- Include Error Handling rules and Fallback Steps:
  - list error categories and per-category handler (retry, route to manual-queue, notify admin, mark as failed)
  - on OCR failures, include a fallback to manual OCR review queue with a specific n8n node list
- Provide Test Payload(s): at least three JSON test payloads covering (1) valid receipt, (2) duplicate receipt, (3) malformed/low-quality image triggering OCR fallback.
- Provide Example API/Webhook response/assertions that can be used to unit test each node.
- Provide a short Implementation Notes section calling out credential storage, rate limiting, PII handling, and audit logging requirements.

Formatting and delivery rules:
- Produce the output in Markdown and structure it exactly as required in "Output Format".
- Use tables for mapping and test payloads when helpful.
- Use inline code-style for expressions and field names.
- When referencing any external API endpoints include an example HTTPS request (method, path, headers, body) and the minimal expected response fragment.
- If any claim requires a choice (e.g., which OCR provider), present 2 practical options and explain trade-offs in one sentence each.

Start by validating the provided inputs. If valid, produce the full workflow spec now.

## Output Format
Output:
1) Overview  
2) Node list (ordered)  
3) Field mapping table(s)  
4) Retries/timeouts + dedupe strategy  
5) Test payload(s)

Ensure each numbered section is present and labeled exactly as above.

## Guardrails
- No “magic nodes”; every transformation and validation must be explicit and described.
- Enforce idempotency and dedupe at the trigger and at each downstream write.
- Require explicit credential scopes and secure storage for secrets; do not embed secrets in the spec.
- Fail-fast on auth errors, retry on transient network errors with exponential backoff, escalate after configured retry limit.
- Validate image MIME type and size at the webhook; reject and respond 400 for invalid formats.
- Keep PII handling auditable: log only allowed fields, mask sensitive fields in logs, and store full receipt images behind secured storage with access logs.
- Provide a manual-queue fallback for any step that exceeds retry limits.
- Avoid polling when webhooks are available; prefer push-first architecture.
- Limit number of external calls per receipt to reduce costs; batch where safe.

## Examples
Mini node list excerpt (format example):
- Webhook Trigger (n8n Webhook)
  - Activation: incoming POST to /webhook/expenses
  - Expected body: `{ "source":"mobile_app", "employee_id":"E123", "receipt_image_url":"https://...", "submitted_at":"2026-01-01T12:00:00Z" }`
  - Idempotency: header `Idempotency-Key` or `idempotency_id` computed as `sha256(source + "_" + source_id + "_" + submitted_at)`
  - On receive: validate `receipt_image_url`, respond 202 with `processing_id`
- HTTP Request (OCR)
  - Call: POST https://api.ocrprovider.com/v1/parse
  - Payload: `{ "image_url": {{$node["Webhook"].json["receipt_image_url"]}} }`
  - Map: `ocr.total_amount` -> `expense.amount`, `ocr.vendor` -> `expense.vendor`, `ocr.date` -> `expense.date`
- IF / Switch (Rule Router)
  - Rule: `expense.amount > 1000` -> route to `Manager Approval Path`
  - Else -> `Auto-Approve Small Expenses` or `Regular Approval Path`
- Human Approval (Email / Slack / In-app)
  - Notify manager, include `Approve` and `Request More Info` links that call back to `/webhook/expenses/approval`

Use this template prompt as a single copy-paste input to your LLM to generate the full n8n workflow blueprint.

Variables

Usage Notes

Not for

Do not include

Expense Approval: n8n Human-in-the-Loop Workflow Blueprint

Generate a complete, operator-grade n8n workflow blueprint for receipt ingestion → OCR → rule routing → approvals → escalation, including mappings, auth, retries, dedupe and test payloads.

Turn this into a working asset in minutes.

Import into Workspace to auto-fill variables, adapt output style, and iterate with OctiAI's prompt editor.

What you'll get

Output format

Markdown

Best used when

Avoid when

Sign in to save, like, or rate this prompt.

Made for

What to fill in

Use the guidance below to complete each placeholder with the right level of detail.

Trigger Event

Provide the key details needed for this variable.

Apps List

Provide the key details needed for this variable.

Auth Constraints

Provide the key details needed for this variable.

Data Schema

Provide the key details needed for this variable.

Escalation Policy

Provide the key details needed for this variable.

Rules

Canonical Examples

Input: Complete brief provided: webhook trigger + apps (AWS S3, Google Drive, Slack, Xero, Jira), auth constraints (OAuth scopes, API keys, IAM role), full incoming payload schema, and escalation policy (2 retries then escalate to Slack/Finance, 24h SLA).

Loading result...

Failed to load output.

Sections: 1) Overview with inputs & notes; 2) Ordered n8n node list (Webhook -> Validate -> Compute idempotency -> Store image -> OCR -> Parse & map -> Router -> Human Approval/Auto-approve -> Accounting write -> Escalation/manual-queue paths); 3) Field mapping tables; 4) Retries/timeouts + dedupe (sha256 idempotency, pHash dedupe); 5) Test payloads + example API assertions.

Why it works: All required inputs were provided, so the prompt returns a full, copy-paste-ready n8n workflow blueprint: ordered nodes, explicit settings and expressions, webhook schema, OCR call examples, rule routing, human-approval callbacks, retries/dedupe strategy, test payloads and implementation notes. Engineers or low-code implementers can implement the n8n nodes and credentials directly from this spec.

Input: Underspecified brief: provided trigger (`POST /webhook/expenses`) and data_schema but missing `apps_list` and `escalation_policy`.

Loading result...

Failed to load output.

Missing required fields — cannot generate full workflow. Provide the following before re-running the prompt. For each missing field an example value is shown.

- `apps_list` (required): list the external apps/integrations the workflow will 

Why it works: The prompt requires all key inputs; when some are missing it should list the missing fields and example values so the operator can re-run with complete inputs. This example demonstrates the guardrail behavior — it does not produce the full spec because required inputs are missing.

Works Best With

This prompt produces best results when you provide: