See llms.txt for all machine-readable content.

Back to Templates

Queue and approve AI-extracted order requests with OpenAI before writing

Quick overview

This workflow accepts order-request text via webhook, uses OpenAI Chat Completions to extract structured fields with quoted evidence and confidence scores, validates the extraction in code, and routes the request to an n8n review form where a human must approve before the record is written to an API.

How it works

  1. Receives a POST request on an n8n webhook (or runs from a manual test sample) containing a source_id and text to process.
  2. Normalizes and validates the input (including generating a review ID and enforcing a maximum text length).
  3. Sends the document to OpenAI Chat Completions with instructions to return JSON fields plus verbatim evidence snippets and confidence scores.
  4. Checks the extracted fields in code for missing required data, low confidence, invalid evidence, and suspicious quantity/date/amount values, and assigns a risk level.
  5. Creates a human-review package and returns a webhook response containing the review ID, flags, risk, and a review-form URL.
  6. Waits up to 72 hours for a reviewer to submit the n8n form with a decision and optional JSON corrections.
  7. Writes the approved record to the configured HTTP endpoint, and otherwise logs the not-written outcome.

Setup

  1. Add an HTTP Header Auth credential for the OpenAI API (Authorization: Bearer <API_KEY>) and select it in the OpenAI request step.
  2. Update the Config values for llm_base_url, llm_model, and write_endpoint, and adjust min_confidence and amount_review_threshold as needed.
  3. If you want reviewer notifications, configure SMTP/email credentials and enable the email step, then set the reviewer to/from email addresses.
  4. Activate the workflow and send a POST payload like {"source_id":"...","text":"..."} to the webhook URL for /webhook/hitl-intake, then open the returned review_form_url to approve or reject.

Requirements

  • n8n 1.x or 2.x (tested on 2.48.8), an OpenAI-compatible Chat Completions API, and the API, sheet or database you will write approved records to. SMTP only if you enable the reviewer email node.

Customization

  • Change the field list in the prompt and in the LABEL/REQUIRED tables for tickets, invoices or applications. Swap Write approved record for Google Sheets, Airtable or a database node.

Additional info

Tested on n8n 2.48.8 with Ollama qwen2.5:7b. Nothing is written without a reviewer choosing "Approve and write"; the write target is a placeholder (https://your-api.example.com/records) that must be set first. Sample documents are synthetic (Alex Rivera / Example Design Studio / [email protected]).