See llms.txt for all machine-readable content.

Back to Templates

Log AI agent runs in hash-chained receipts with OpenAI and Data Tables

Last update

Last update 7 hours ago

Categories

Share


Quick overview

This workflow exposes webhook endpoints to run an OpenAI-powered agent per client, log each run into an n8n Data Table as a SHA-256 hash chain, and email daily integrity reports and anchors, with an additional verification endpoint clients can query.

How it works

  1. Receives a POST webhook request with client_id and prompt, validates the client and prompt rules, and rejects invalid requests immediately.
  2. Runs a LangChain AI agent using OpenAI Chat and an optional Calculator tool to generate an answer or capture an agent failure.
  3. Builds a log entry that hashes the prompt and answer (optionally storing clipped text), counts model/tool calls, and sets the outcome as ok, refused, or error.
  4. Reads the latest entry for that client from the agent_run_log n8n Data Table, links the new entry to the previous hash, computes a new entry_hash, and appends it to the table.
  5. Re-reads the just-written area to confirm the entry is the canonical next sequence (retrying with a short backoff on collisions), then returns the answer or error along with a receipt containing seq and entry_hash.
  6. If the run cannot be reliably logged, withholds the agent output, returns HTTP 503 to the caller, and emails the owner with the failure details.
  7. Runs daily on a schedule to recompute and verify every client’s hash chain in agent_run_log, stores new anchors in agent_run_anchors, and emails the owner a report (or a failure notice if the tables can’t be read).
  8. Receives a GET webhook request for verification, loads that client’s log and anchors from the Data Tables, verifies chain integrity and optional receipt fields, and returns a hash-and-count-only status response.

Setup

  1. Create two n8n Data Tables named agent_run_log and agent_run_anchors with the columns and data types expected by the workflow (keeping logged_at and anchored_at as strings).
  2. Add an OpenAI credential for the OpenAI Chat model used by the LangChain agent.
  3. Configure Header Auth for both webhooks and update your calling app to send the required header and payload/query parameters.
  4. Add SMTP/Email credentials for the email send steps and set owner_email and sender_email in both Settings sections.
  5. Review and adjust logging and guardrail settings (allowed/paused clients, prompt length, retries, and whether to store prompt/answer text) before activating the workflow.

Additional info

Who's it for

Agencies and freelancers who let an AI agent draft replies for clients but need the client's yes before anything is sent. The approver needs no n8n account.

How it works

Your helpdesk or another workflow POSTs the customer's message to the webhook. An AI Agent drafts the reply in the client's voice, and the draft gets a SHA-256 fingerprint. The approver gets an email with a link to a short form: approve, edit and approve, request changes or reject. Opening the link only shows the form, so link scanners can't approve. No answer by the deadline means expired, never approved. Every decision is stored in a Data table. Just before sending, the text is fingerprinted again; if it differs from the approved text, nothing is sent.

How to set up

  1. Create the Data tables approval_clients and approval_requests (columns in the sticky note).
  2. Add OpenAI, SMTP and Header Auth credentials.
  3. Fill in Settings: sender, deadline, reminder, revision rounds and model.
  4. Publish the workflow and send a test request with curl.

Requirements

n8n with Data tables, an OpenAI API key and SMTP.

How to customize

Replace "Send the approved reply" with your own step (Gmail, a helpdesk reply, a CMS post) and keep the fingerprint check in front of it.

Prepared with AI assistance. Editorial responsibility: PowerQuant ApS.